@@ -66,6 +66,43 @@ class Babble_Languages extends Babble_Plugin {
66
66
**/
67
67
protected $ errors ;
68
68
69
+ /**
70
+ * Array of language codes where the language writes right-to-left.
71
+ *
72
+ * Based primarily on GlotPress' list of locales and Wikipedia's article on RTL:
73
+ *
74
+ * @link https://glotpress.trac.wordpress.org/browser/trunk/locales/locales.php
75
+ * @link https://en.wikipedia.org/wiki/Right-to-left
76
+ *
77
+ * @var array
78
+ */
79
+ protected static $ rtl_languages = array (
80
+ 'ar ' , // Arabic / العربية
81
+ 'arc ' , // Aramaic
82
+ 'arq ' , // Algerian Arabic / الدارجة الجزايرية
83
+ 'azb ' , // South Azerbaijani / گؤنئی آذربایجان
84
+ 'az_TR ' , // Azerbaijani (Turkey) / Azərbaycan Türkcəsi
85
+ 'bcc ' , // Balochi Southern / بلوچی مکرانی
86
+ 'bqi ' , // Bakthiari / بختياري
87
+ 'ckb ' , // Sorani Kurdish / کوردی
88
+ 'dv ' , // Dhivehi
89
+ 'fa ' , // Persian / فارسی
90
+ 'fa_IR ' , // Persian / فارسی
91
+ 'fa_AF ' , // Persian (Afghanistan) / (افغانستان) فارسی
92
+ 'glk ' , // Gilaki / گیلکی
93
+ 'ha ' , // Hausa / هَوُسَ
94
+ 'haz ' , // Hazaragi / هزاره گی
95
+ 'he ' , // Hebrew / עִבְרִית
96
+ 'he_IL ' , // Hebrew / עִבְרִית
97
+ 'mzn ' , // Mazanderani / مازِرونی
98
+ 'pnb ' , // Western Punjabi / پنجابی
99
+ 'ps ' , // Pashto / پښتو
100
+ 'sd ' , // Sindhi / سنڌي
101
+ 'ug ' , // Uyghur / ئۇيغۇرچە
102
+ 'ur ' , // Urdu / اردو
103
+ 'yi ' , // Yiddish / ייִדיש'
104
+ );
105
+
69
106
/**
70
107
* Setup any add_action or add_filter calls. Initiate properties.
71
108
*
@@ -443,7 +480,7 @@ protected function parse_available_languages() {
443
480
'name ' => $ this ->format_code_lang ( $ prefix ),
444
481
'code ' => $ lang_code ,
445
482
'url_prefix ' => $ prefix ,
446
- 'text_direction ' => $ this -> is_rtl ( $ lang_code ),
483
+ 'text_direction ' => ( self :: is_rtl ( $ lang_code ) ? ' rtl ' : ' ltr ' ),
447
484
);
448
485
// Cast to an object, in case we want to start using actual classes
449
486
// at some point in the future.
@@ -462,21 +499,13 @@ protected function parse_available_languages() {
462
499
}
463
500
464
501
/**
465
- * Parse (DON'T require or include) the [lang_code].php locale file in the languages
466
- * directory to work if the specified language is right to left. (We can't include or
467
- * require because it may contain function names which clash with other locale files.)
502
+ * Is the given language a right-to-left language?
468
503
*
469
- * @param string $lang The language code to retrieve RTL info for
504
+ * @param string $lang_code The language code to retrieve RTL info for
470
505
* @return bool True if the language is RTL
471
506
**/
472
- protected function is_rtl ( $ lang ) {
473
- $ locale_file = WP_LANG_DIR . "/ $ lang.php " ;
474
- if ( ( 0 === validate_file ( $ lang ) ) && is_readable ( $ locale_file ) ) {
475
- $ locale_file_code = file_get_contents ( $ locale_file );
476
- // Regex to find something looking like: $text_direction = 'rtl';
477
- return ( (bool ) preg_match ( '/\$text_direction\s?=\s?[ \'|"]rtl[ \'|"]\s?;/i ' , $ locale_file_code ) ) ? 'rtl ' : 'ltr ' ;
478
- }
479
- return 'ltr ' ;
507
+ public static function is_rtl ( $ lang_code ) {
508
+ return in_array ( $ lang_code , self ::$ rtl_languages , true );
480
509
}
481
510
482
511
/**
0 commit comments