aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-02-24 19:26:57 +0100
committerArthur <arthur@hoa.ro>2016-02-24 19:26:57 +0100
commitfa40b43f60c5367fc28a22d05c3f344ce39340c6 (patch)
tree5398143a2b92e365b20667822335d330723c1646 /application
parent6c3d6a31f413862941fe514e7167c04fe71ba1a7 (diff)
parent7eb0a832018621b3662f9fb5c45c0a67f5936088 (diff)
downloadShaarli-fa40b43f60c5367fc28a22d05c3f344ce39340c6.tar.gz
Shaarli-fa40b43f60c5367fc28a22d05c3f344ce39340c6.tar.zst
Shaarli-fa40b43f60c5367fc28a22d05c3f344ce39340c6.zip
Merge pull request #492 from ArthurHoaro/locale-sort-fix
Fixes #481: tag cloud fatal error
Diffstat (limited to 'application')
-rw-r--r--application/Utils.php25
1 files changed, 25 insertions, 0 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)
213function format_description($description, $redirector) { 213function 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 **/
223function 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