Lock page when changes are done in the SQL editor
[phpmyadmin.git] / libraries / Language.php
blob8dd53ed6bea6b5b08cc1bccf942b7c171eb2dec1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Hold the PMA\libraries\LanguageManager class
6 * @package PhpMyAdmin
7 */
8 namespace PMA\libraries;
10 use PMA\libraries\LanguageManager;
13 /**
14 * Language object
16 * @package PhpMyAdmin
18 class Language
20 protected $code;
21 protected $name;
22 protected $native;
23 protected $regex;
24 protected $mysql;
26 /**
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)
38 $this->code = $code;
39 $this->name = $name;
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;
48 /**
49 * Returns native name for language
51 * @return string
53 public function getNativeName()
55 return $this->native;
58 /**
59 * Returns English name for language
61 * @return string
63 public function getEnglishName()
65 return $this->name;
68 /**
69 * Returns verbose name for language
71 * @return string
73 public function getName()
75 if (! empty($this->native)) {
76 return $this->native . ' - ' . $this->name;
77 } else {
78 return $this->name;
82 /**
83 * Returns language code
85 * @return string
87 public function getCode()
89 return $this->code;
92 /**
93 * Returns MySQL locale code, can be empty
95 * @return string
97 public function getMySQLLocale()
99 return $this->mysql;
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.
117 * @return bool
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
129 * @return bool
131 public function matchesAcceptLanguage($header)
133 $pattern = '/^('
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
144 * @return bool
146 public function matchesUserAgent($header)
148 $pattern = '/(\(|\[|;[[:space:]])('
149 . addcslashes($this->regex, '/')
150 . ')(;|\]|\))/i';
151 return preg_match($pattern, $header);
155 * Checks whether langauge is RTL
157 * @return bool
159 public function isRTL()
161 return in_array($this->code, array('ar', 'fa', 'he', 'ur'));
165 * Activates given translation
167 * @return bool
169 public function activate()
171 $GLOBALS['lang'] = $this->code;
173 // Set locale
174 _setlocale(0, $this->code);
175 _bindtextdomain('phpmyadmin', LOCALE_PATH);
176 _textdomain('phpmyadmin');
178 /* Text direction for language */
179 if ($this->isRTL()) {
180 $GLOBALS['text_dir'] = 'rtl';
181 } else {
182 $GLOBALS['text_dir'] = 'ltr';
185 /* TCPDF */
186 $GLOBALS['l'] = array();
188 /* TCPDF settings */
189 $GLOBALS['l']['a_meta_charset'] = 'UTF-8';
190 $GLOBALS['l']['a_meta_dir'] = $GLOBALS['text_dir'];
191 $GLOBALS['l']['a_meta_language'] = $this->code;
193 /* TCPDF translations */
194 $GLOBALS['l']['w_page'] = __('Page number:');
196 /* Show possible warnings from langauge selection */
197 LanguageManager::getInstance()->showWarnings();