]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't force the use of Accept-Language anymore 4249/head
authorJoas Schilling <coding@schilljs.com>
Fri, 7 Apr 2017 08:52:17 +0000 (10:52 +0200)
committerJoas Schilling <coding@schilljs.com>
Fri, 7 Apr 2017 09:10:04 +0000 (11:10 +0200)
This is not intended anymore, since it falls back to force english
when the header is not set. Also 0228bc6e66cbcb2848eacb41f1de6e7f63ebcb65
makes clear that the order should be:

1. User setting
2. Accept language
3. Admin default

This is the case since the commit from above, unless via OCS and DAV.
Both forced to accept-language falling back to english.
By removing the force, it now also matches the w3 priority list:
https://www.w3.org/International/questions/qa-lang-priorities

Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/L10N/Factory.php
lib/public/L10N/IFactory.php
ocs/v1.php
remote.php
tests/lib/L10N/FactoryTest.php

index 8aad395065cd3ccaa8d33437d1886f299db44bbf..581ca3fb5d173ce95ab4169d3a928bbe100458f3 100644 (file)
@@ -270,24 +270,6 @@ class Factory implements IFactory {
                throw new LanguageNotFoundException();
        }
 
-       /**
-        * @param string|null $app App id or null for core
-        * @return string
-        */
-       public function setLanguageFromRequest($app = null) {
-
-               try {
-                       $requestLanguage = $this->getLanguageFromRequest($app);
-               } catch (LanguageNotFoundException $e) {
-                       $requestLanguage = 'en';
-               }
-
-               if ($app === null && !$this->requestLanguage) {
-                       $this->requestLanguage = $requestLanguage;
-               }
-               return $requestLanguage;
-       }
-
        /**
         * Checks if $sub is a subdirectory of $parent
         *
index 0d6e583c7e58a54ada10de7e3ccf71c0ad5caede..b5f93c2389c0c0cc5764f7bf5f67e66bb1f1c873 100644 (file)
@@ -61,14 +61,6 @@ interface IFactory {
         */
        public function languageExists($app, $lang);
 
-       /**
-        * @param string|null $app App id or null for core
-        * @return string
-        * @since 9.0.0
-        */
-       public function setLanguageFromRequest($app = null);
-
-
        /**
         * Creates a function from the plural string
         *
index e92250b7e38ed49b70c818309e08aeef834f8b75..80df64f4ed6182aac47ed730c36fff73e1ee3ee1 100644 (file)
@@ -54,9 +54,6 @@ try {
        // load all apps to get all api routes properly setup
        OC_App::loadApps();
 
-       // force language as given in the http request
-       \OC::$server->getL10NFactory()->setLanguageFromRequest();
-
        OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo());
        return;
 } catch (ResourceNotFoundException $e) {
index e5bd3bb8fed0d7b97ff042712f8dfb1d68516688..8e74967365df576309536b300b3f8b40519db17f 100644 (file)
@@ -136,9 +136,6 @@ try {
                throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND);
        }
 
-       // force language as given in the http request
-       \OC::$server->getL10NFactory()->setLanguageFromRequest();
-
        $file=ltrim($file, '/');
 
        $parts=explode('/', $file, 2);
index 5e422758cb4883d3078f0279800939ff03a12a83..77a56b5f945defa75cd313e809a494913d12cf45 100644 (file)
@@ -9,6 +9,7 @@
 namespace Test\L10N;
 
 use OC\L10N\Factory;
+use OC\L10N\LanguageNotFoundException;
 use OCP\IConfig;
 use OCP\IRequest;
 use OCP\IUser;
@@ -339,26 +340,22 @@ class FactoryTest extends TestCase {
        public function dataSetLanguageFromRequest() {
                return [
                        // Language is available
-                       [null, 'de', null, ['de'], 'de', 'de'],
-                       [null, 'de,en', null, ['de'], 'de', 'de'],
-                       [null, 'de-DE,en-US;q=0.8,en;q=0.6', null, ['de'], 'de', 'de'],
+                       [null, 'de', ['de'], 'de'],
+                       [null, 'de,en', ['de'], 'de'],
+                       [null, 'de-DE,en-US;q=0.8,en;q=0.6', ['de'], 'de'],
                        // Language is not available
-                       [null, 'de', null, ['ru'], 'en', 'en'],
-                       [null, 'de,en', null, ['ru', 'en'], 'en', 'en'],
-                       [null, 'de-DE,en-US;q=0.8,en;q=0.6', null, ['ru', 'en'], 'en', 'en'],
-                       // Language is available, but request language is set
-                       [null, 'de', 'ru', ['de'], 'de', 'ru'],
-                       [null, 'de,en', 'ru', ['de'], 'de', 'ru'],
-                       [null, 'de-DE,en-US;q=0.8,en;q=0.6', 'ru', ['de'], 'de', 'ru'],
-
-                       // Request lang should not be set for apps: Language is available
-                       ['files_pdfviewer', 'de', null, ['de'], 'de', ''],
-                       ['files_pdfviewer', 'de,en', null, ['de'], 'de', ''],
-                       ['files_pdfviewer', 'de-DE,en-US;q=0.8,en;q=0.6', null, ['de'], 'de', ''],
-                       // Request lang should not be set for apps: Language is not available
-                       ['files_pdfviewer', 'de', null, ['ru'], 'en', ''],
-                       ['files_pdfviewer', 'de,en', null, ['ru', 'en'], 'en', ''],
-                       ['files_pdfviewer', 'de-DE,en-US;q=0.8,en;q=0.6', null, ['ru', 'en'], 'en', ''],
+                       [null, 'de', ['ru'], new LanguageNotFoundException()],
+                       [null, 'de,en', ['ru', 'en'], 'en'],
+                       [null, 'de-DE,en-US;q=0.8,en;q=0.6', ['ru', 'en'], 'en'],
+
+                       // Language for app
+                       ['files_pdfviewer', 'de', ['de'], 'de'],
+                       ['files_pdfviewer', 'de,en', ['de'], 'de'],
+                       ['files_pdfviewer', 'de-DE,en-US;q=0.8,en;q=0.6', ['de'], 'de'],
+                       // Language for app is not available
+                       ['files_pdfviewer', 'de', ['ru'], new LanguageNotFoundException()],
+                       ['files_pdfviewer', 'de,en', ['ru', 'en'], 'en'],
+                       ['files_pdfviewer', 'de-DE,en-US;q=0.8,en;q=0.6', ['ru', 'en'], 'en'],
                ];
        }
 
@@ -367,12 +364,10 @@ class FactoryTest extends TestCase {
         *
         * @param string|null $app
         * @param string $header
-        * @param string|null $requestLanguage
         * @param string[] $availableLanguages
         * @param string $expected
-        * @param string $expectedLang
         */
-       public function testSetLanguageFromRequest($app, $header, $requestLanguage, array $availableLanguages, $expected, $expectedLang) {
+       public function testGetLanguageFromRequest($app, $header, array $availableLanguages, $expected) {
                $factory = $this->getFactory(['findAvailableLanguages']);
                $factory->expects($this->once())
                        ->method('findAvailableLanguages')
@@ -384,11 +379,12 @@ class FactoryTest extends TestCase {
                        ->with('ACCEPT_LANGUAGE')
                        ->willReturn($header);
 
-               if ($requestLanguage !== null) {
-                       $this->invokePrivate($factory, 'requestLanguage', [$requestLanguage]);
+               if ($expected instanceof LanguageNotFoundException) {
+                       $this->setExpectedException(LanguageNotFoundException::class);
+                       self::invokePrivate($factory, 'getLanguageFromRequest', [$app]);
+               } else {
+                       $this->assertSame($expected, self::invokePrivate($factory, 'getLanguageFromRequest', [$app]), 'Asserting returned language');
                }
-               $this->assertSame($expected, $factory->setLanguageFromRequest($app), 'Asserting returned language');
-               $this->assertSame($expectedLang, $this->invokePrivate($factory, 'requestLanguage'), 'Asserting stored language');
        }
 
        public function dataGetL10nFilesForApp() {