HtmlDir.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ meCgfTf4AemfULl7/+ll/YKP0bsWQhSIu5wlDUD4tDI=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2015 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.4
  11. */
  12. /**
  13. * add direction to html dir tag
  14. * active locale is retrieved from translate adapter
  15. */
  16. namespace Cube\View\Helper;
  17. class HtmlDir extends AbstractHelper
  18. {
  19. /**
  20. * directions
  21. */
  22. const LTR = 'ltr';
  23. const RTL = 'rtl';
  24. /**
  25. * rtl locales
  26. */
  27. protected $_rtlLocales = array(
  28. 'Arabic (Algeria)' => 'ar_DZ',
  29. 'Arabic (Bahrain)' => 'ar_BH',
  30. 'Arabic (Egypt)' => 'ar_EG',
  31. 'Arabic (Iraq)' => 'ar_IQ',
  32. 'Arabic (Jordan)' => 'ar_JO',
  33. 'Arabic (Kuwait)' => 'ar_KW',
  34. 'Arabic (Lebanon)' => 'ar_LB',
  35. 'Arabic (Libya)' => 'ar_LY',
  36. 'Arabic (Morocco)' => 'ar_MA',
  37. 'Arabic (Oman)' => 'ar_OM',
  38. 'Arabic (Qatar)' => 'ar_QA',
  39. 'Arabic (Saudi Arabia)' => 'ar_SA',
  40. 'Arabic (Sudan)' => 'ar_SD',
  41. 'Arabic (Syria)' => 'ar_SY',
  42. 'Arabic (Tunisia)' => 'ar_TN',
  43. 'Arabic (United Arab Emirates)' => 'ar_AE',
  44. 'Arabic (Yemen)' => 'ar_YE',
  45. 'Arabic' => 'ar',
  46. 'Farsi (Iran)' => 'fa_IR',
  47. 'Hebrew (Israel)' => 'iw_IL',
  48. 'Hebrew' => 'iw',
  49. );
  50. /**
  51. *
  52. * html dir method
  53. *
  54. * @return string
  55. */
  56. public function htmlDir()
  57. {
  58. $locale = $this->getTranslate()->getLocale();
  59. if (!empty($locale)) {
  60. if (in_array($locale, $this->_rtlLocales)) {
  61. return self::RTL;
  62. }
  63. }
  64. return self::LTR;
  65. }
  66. }