diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-02-19 20:14:06 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-02-19 20:14:06 +0100 |
commit | 7b63e4ca09f58b3b056bd2b8f2d8a4157537f274 (patch) | |
tree | ed16ac841e7043c43502ac554ebbbca2278298b4 | |
parent | bfec695df1205864b46ca7175e1598b184602687 (diff) | |
download | Shaarli-7b63e4ca09f58b3b056bd2b8f2d8a4157537f274.tar.gz Shaarli-7b63e4ca09f58b3b056bd2b8f2d8a4157537f274.tar.zst Shaarli-7b63e4ca09f58b3b056bd2b8f2d8a4157537f274.zip |
Apply the locale to all categories and move autolocale to Utils.php
-rw-r--r-- | application/Utils.php | 25 | ||||
-rw-r--r-- | index.php | 22 |
2 files changed, 26 insertions, 21 deletions
diff --git a/application/Utils.php b/application/Utils.php index 10d60698..91e28a68 100644 --- a/application/Utils.php +++ b/application/Utils.php | |||
@@ -213,3 +213,28 @@ function space2nbsp($text) | |||
213 | function format_description($description, $redirector) { | 213 | function format_description($description, $redirector) { |
214 | return nl2br(space2nbsp(text2clickable($description, $redirector))); | 214 | return nl2br(space2nbsp(text2clickable($description, $redirector))); |
215 | } | 215 | } |
216 | |||
217 | /** | ||
218 | * Sniff browser language to set the locale automatically. | ||
219 | * Note that is may not work on your server if the corresponding locale is not installed. | ||
220 | * | ||
221 | * @param string $headerLocale Locale send in HTTP headers (e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"). | ||
222 | **/ | ||
223 | function autoLocale($headerLocale) | ||
224 | { | ||
225 | // Default if browser does not send HTTP_ACCEPT_LANGUAGE | ||
226 | $attempts = array('en_US'); | ||
227 | if (isset($headerLocale)) { | ||
228 | // (It's a bit crude, but it works very well. Preferred language is always presented first.) | ||
229 | if (preg_match('/([a-z]{2})-?([a-z]{2})?/i', $headerLocale, $matches)) { | ||
230 | $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : ''); | ||
231 | $attempts = array( | ||
232 | $loc.'.UTF-8', $loc, str_replace('_', '-', $loc).'.UTF-8', str_replace('_', '-', $loc), | ||
233 | $loc . '_' . strtoupper($loc).'.UTF-8', $loc . '_' . strtoupper($loc), | ||
234 | $loc . '_' . $loc.'.UTF-8', $loc . '_' . $loc, $loc . '-' . strtoupper($loc).'.UTF-8', | ||
235 | $loc . '-' . strtoupper($loc), $loc . '-' . $loc.'.UTF-8', $loc . '-' . $loc | ||
236 | ); | ||
237 | } | ||
238 | } | ||
239 | setlocale(LC_ALL, $attempts); | ||
240 | } \ No newline at end of file | ||
@@ -268,7 +268,7 @@ $GLOBALS['redirector'] = !empty($GLOBALS['redirector']) ? escape($GLOBALS['redir | |||
268 | // a token depending of deployment salt, user password, and the current ip | 268 | // a token depending of deployment salt, user password, and the current ip |
269 | define('STAY_SIGNED_IN_TOKEN', sha1($GLOBALS['hash'].$_SERVER["REMOTE_ADDR"].$GLOBALS['salt'])); | 269 | define('STAY_SIGNED_IN_TOKEN', sha1($GLOBALS['hash'].$_SERVER["REMOTE_ADDR"].$GLOBALS['salt'])); |
270 | 270 | ||
271 | autoLocale(); // Sniff browser language and set date format accordingly. | 271 | autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); // Sniff browser language and set date format accordingly. |
272 | header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling. | 272 | header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling. |
273 | 273 | ||
274 | //================================================================================================== | 274 | //================================================================================================== |
@@ -315,26 +315,6 @@ function setup_login_state() { | |||
315 | } | 315 | } |
316 | $userIsLoggedIn = setup_login_state(); | 316 | $userIsLoggedIn = setup_login_state(); |
317 | 317 | ||
318 | |||
319 | // ------------------------------------------------------------------------------------------ | ||
320 | // Sniff browser language to display dates in the right format automatically. | ||
321 | // (Note that is may not work on your server if the corresponding local is not installed.) | ||
322 | function autoLocale() | ||
323 | { | ||
324 | $attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE | ||
325 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3" | ||
326 | { // (It's a bit crude, but it works very well. Preferred language is always presented first.) | ||
327 | if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) { | ||
328 | $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : ''); | ||
329 | $attempts = array($loc.'.UTF-8', $loc, str_replace('_', '-', $loc).'.UTF-8', str_replace('_', '-', $loc), | ||
330 | $loc . '_' . strtoupper($loc).'.UTF-8', $loc . '_' . strtoupper($loc), | ||
331 | $loc . '_' . $loc.'.UTF-8', $loc . '_' . $loc, $loc . '-' . strtoupper($loc).'.UTF-8', | ||
332 | $loc . '-' . strtoupper($loc), $loc . '-' . $loc.'.UTF-8', $loc . '-' . $loc); | ||
333 | } | ||
334 | } | ||
335 | setlocale(LC_TIME, $attempts); // LC_TIME = Set local for date/time format only. | ||
336 | } | ||
337 | |||
338 | // ------------------------------------------------------------------------------------------ | 318 | // ------------------------------------------------------------------------------------------ |
339 | // PubSubHubbub protocol support (if enabled) [UNTESTED] | 319 | // PubSubHubbub protocol support (if enabled) [UNTESTED] |
340 | // (Source: http://aldarone.fr/les-flux-rss-shaarli-et-pubsubhubbub/ ) | 320 | // (Source: http://aldarone.fr/les-flux-rss-shaarli-et-pubsubhubbub/ ) |