summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/locales.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers/locales.php')
-rw-r--r--modules/gallery/helpers/locales.php34
1 files changed, 33 insertions, 1 deletions
diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php
index faec7816..17286adf 100644
--- a/modules/gallery/helpers/locales.php
+++ b/modules/gallery/helpers/locales.php
@@ -236,4 +236,36 @@ class locales_Core {
}
return array(null, 0);
}
-} \ No newline at end of file
+
+ static function set_request_locale() {
+ // 1. Check the session specific preference (cookie)
+ $locale = self::cookie_locale();
+ // 2. Check the user's preference
+ if (!$locale) {
+ $locale = user::active()->locale;
+ }
+ // 3. Check the browser's / OS' preference
+ if (!$locale) {
+ $locale = locales::locale_from_http_request();
+ }
+ // If we have any preference, override the site's default locale
+ if ($locale) {
+ I18n::instance()->locale($locale);
+ }
+ }
+
+ static function cookie_locale() {
+ $cookie_data = Input::instance()->cookie("g_locale");
+ $locale = null;
+ if ($cookie_data) {
+ if (preg_match("/^([a-z]{2,3}(?:_[A-Z]{2})?)$/", trim($cookie_data), $matches)) {
+ $requested_locale = $matches[1];
+ $installed_locales = locales::installed();
+ if (isset($installed_locales[$requested_locale])) {
+ $locale = $requested_locale;
+ }
+ }
+ }
+ return $locale;
+ }
+}