2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Hold the PMA\libraries\LanguageManager class
8 namespace PMA\libraries
;
10 use PMA\libraries\LanguageManager
;
27 * Constructs the Language object
29 * @param string $code Language code
30 * @param string $name English name
31 * @param string $native Native name
32 * @param string $regex Match regullar expression
33 * @param string $mysql MySQL locale code
36 public function __construct($code, $name, $native, $regex, $mysql)
40 $this->native
= $native;
41 if (strpos($regex, '[-_]') === false) {
42 $regex = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $regex);
44 $this->regex
= $regex;
45 $this->mysql
= $mysql;
49 * Returns native name for language
53 public function getNativeName()
59 * Returns English name for language
63 public function getEnglishName()
69 * Returns verbose name for language
73 public function getName()
75 if (! empty($this->native
)) {
76 return $this->native
. ' - ' . $this->name
;
83 * Returns language code
87 public function getCode()
93 * Returns MySQL locale code, can be empty
97 public function getMySQLLocale()
103 * Compare function used for sorting
105 * @param Language $other Other object to compare
107 * @return int same as strcmp
109 public function cmp($other)
111 return strcmp($this->name
, $other->name
);
115 * Checks whether language is currently active.
119 public function isActive()
121 return $GLOBALS['lang'] == $this->code
;
125 * Checks whether language matches HTTP header Accept-Language.
127 * @param string $header Header content
131 public function matchesAcceptLanguage($header)
134 . addcslashes($this->regex
, '/')
135 . ')(;q=[0-9]\\.[0-9])?$/i';
136 return preg_match($pattern, $header);
140 * Checks whether language matches HTTP header User-Agent
142 * @param string $header Header content
146 public function matchesUserAgent($header)
148 $pattern = '/(\(|\[|;[[:space:]])('
149 . addcslashes($this->regex
, '/')
151 return preg_match($pattern, $header);
155 * Checks whether langauge is RTL
159 public function isRTL()
161 return in_array($this->code
, array('ar', 'fa', 'he', 'ur'));
165 * Activates given translation
169 public function activate()
171 $GLOBALS['lang'] = $this->code
;
174 _setlocale(LC_MESSAGES
, $this->code
);
175 _bindtextdomain('phpmyadmin', LOCALE_PATH
);
176 _bind_textdomain_codeset('phpmyadmin', 'UTF-8');
177 _textdomain('phpmyadmin');
179 /* Text direction for language */
180 if ($this->isRTL()) {
181 $GLOBALS['text_dir'] = 'rtl';
183 $GLOBALS['text_dir'] = 'ltr';
187 $GLOBALS['l'] = array();
190 $GLOBALS['l']['a_meta_charset'] = 'UTF-8';
191 $GLOBALS['l']['a_meta_dir'] = $GLOBALS['text_dir'];
192 $GLOBALS['l']['a_meta_language'] = $this->code
;
194 /* TCPDF translations */
195 $GLOBALS['l']['w_page'] = __('Page number:');
197 /* Show possible warnings from langauge selection */
198 LanguageManager
::getInstance()->showWarnings();