summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-02-24 17:42:26 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-03-09 10:38:38 +0100
commit2367797c17aafe0f0570477ff653894f3033e97c (patch)
treea838d249abd8d65bfb985309e6d080fb65667210 /lib
parent33b11682f9826346f48b7587161dc5a43944a063 (diff)
downloadnextcloud-server-2367797c17aafe0f0570477ff653894f3033e97c.tar.gz
nextcloud-server-2367797c17aafe0f0570477ff653894f3033e97c.zip
Respect http header 'Accept-Language' on ocs and remote.php calls
Diffstat (limited to 'lib')
-rw-r--r--lib/private/l10n.php78
1 files changed, 43 insertions, 35 deletions
diff --git a/lib/private/l10n.php b/lib/private/l10n.php
index 4e9316c333e..4fd4a617be8 100644
--- a/lib/private/l10n.php
+++ b/lib/private/l10n.php
@@ -80,6 +80,48 @@ class OC_L10N implements \OCP\IL10N {
}
/**
+ * @param $app
+ * @return string
+ */
+ public static function setLanguageFromRequest($app = null) {
+ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
+ if (is_array($app)) {
+ $available = $app;
+ } else {
+ $available = self::findAvailableLanguages($app);
+ }
+
+ // E.g. make sure that 'de' is before 'de_DE'.
+ sort($available);
+
+ $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
+ foreach ($preferences as $preference) {
+ list($preferred_language) = explode(';', $preference);
+ $preferred_language = str_replace('-', '_', $preferred_language);
+ foreach ($available as $available_language) {
+ if ($preferred_language === strtolower($available_language)) {
+ if (is_null($app)) {
+ self::$language = $available_language;
+ }
+ return $available_language;
+ }
+ }
+ foreach ($available as $available_language) {
+ if (substr($preferred_language, 0, 2) === $available_language) {
+ if (is_null($app)) {
+ self::$language = $available_language;
+ }
+ return $available_language;
+ }
+ }
+ }
+ }
+
+ // Last try: English
+ return 'en';
+ }
+
+ /**
* @param $transFile
* @param bool $mergeTranslations
* @return bool
@@ -403,41 +445,7 @@ class OC_L10N implements \OCP\IL10N {
return $default_language;
}
- if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- if(is_array($app)) {
- $available = $app;
- } else {
- $available = self::findAvailableLanguages($app);
- }
-
- // E.g. make sure that 'de' is before 'de_DE'.
- sort($available);
-
- $preferences = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
- foreach($preferences as $preference) {
- list($preferred_language) = explode(';', $preference);
- $preferred_language = str_replace('-', '_', $preferred_language);
- foreach($available as $available_language) {
- if ($preferred_language === strtolower($available_language)) {
- if (is_null($app)) {
- self::$language = $available_language;
- }
- return $available_language;
- }
- }
- foreach($available as $available_language) {
- if (substr($preferred_language, 0, 2) === $available_language) {
- if (is_null($app)) {
- self::$language = $available_language;
- }
- return $available_language;
- }
- }
- }
- }
-
- // Last try: English
- return 'en';
+ return self::setLanguageFromRequest($app);
}
/**