aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/Utils.php')
-rw-r--r--application/Utils.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/application/Utils.php b/application/Utils.php
index 868946df..3d819716 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -229,3 +229,28 @@ function space2nbsp($text)
229function format_description($description, $redirector) { 229function format_description($description, $redirector) {
230 return nl2br(space2nbsp(text2clickable($description, $redirector))); 230 return nl2br(space2nbsp(text2clickable($description, $redirector)));
231} 231}
232
233/**
234 * Sniff browser language to set the locale automatically.
235 * Note that is may not work on your server if the corresponding locale is not installed.
236 *
237 * @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").
238 **/
239function autoLocale($headerLocale)
240{
241 // Default if browser does not send HTTP_ACCEPT_LANGUAGE
242 $attempts = array('en_US');
243 if (isset($headerLocale)) {
244 // (It's a bit crude, but it works very well. Preferred language is always presented first.)
245 if (preg_match('/([a-z]{2})-?([a-z]{2})?/i', $headerLocale, $matches)) {
246 $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
247 $attempts = array(
248 $loc.'.UTF-8', $loc, str_replace('_', '-', $loc).'.UTF-8', str_replace('_', '-', $loc),
249 $loc . '_' . strtoupper($loc).'.UTF-8', $loc . '_' . strtoupper($loc),
250 $loc . '_' . $loc.'.UTF-8', $loc . '_' . $loc, $loc . '-' . strtoupper($loc).'.UTF-8',
251 $loc . '-' . strtoupper($loc), $loc . '-' . $loc.'.UTF-8', $loc . '-' . $loc
252 );
253 }
254 }
255 setlocale(LC_ALL, $attempts);
256} \ No newline at end of file