diff options
Diffstat (limited to 'settings')
-rw-r--r-- | settings/Controller/PersonalController.php | 87 | ||||
-rw-r--r-- | settings/js/personal.js | 38 | ||||
-rw-r--r-- | settings/personal.php | 109 | ||||
-rw-r--r-- | settings/routes.php | 1 | ||||
-rw-r--r-- | settings/templates/personal.php | 2 |
5 files changed, 82 insertions, 155 deletions
diff --git a/settings/Controller/PersonalController.php b/settings/Controller/PersonalController.php deleted file mode 100644 index 696c0a5c414..00000000000 --- a/settings/Controller/PersonalController.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php -/** - * @copyright Roeland Jago Douma <roeland@famdouma.nl> - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -namespace OC\Settings\Controller; - -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\JSONResponse; -use OCP\IConfig; -use OCP\IL10N; -use OCP\IRequest; -use OCP\L10N\IFactory; - -class PersonalController extends Controller { - /** @var IFactory */ - private $l10nFactory; - - /** @var string */ - private $userId; - - /** @var IConfig */ - private $config; - - /** @var IL10N */ - private $l; - - /** - * PersonalController constructor. - * - * @param string $appName - * @param IRequest $request - * @param IFactory $l10nFactory - * @param $userId - * @param IConfig $config - * @param IL10N $l - */ - public function __construct($appName, - IRequest $request, - IFactory $l10nFactory, - $userId, - IConfig $config, - IL10N $l) { - parent::__construct($appName, $request); - - $this->l10nFactory = $l10nFactory; - $this->userId = $userId; - $this->config = $config; - $this->l = $l; - } - - /** - * @NoAdminRequired - * @NoSubadminRequired - * @param string $lang - * @return JSONResponse - */ - public function setLanguage($lang) { - if ($lang !== '') { - $languagesCodes = $this->l10nFactory->findAvailableLanguages(); - if (array_search($lang, $languagesCodes) || $lang === 'en') { - $this->config->setUserValue($this->userId, 'core', 'lang', $lang); - return new JSONResponse([]); - } - } - - return new JSONResponse(['message' => $this->l->t('Invalid request')], Http::STATUS_BAD_REQUEST); - } -} diff --git a/settings/js/personal.js b/settings/js/personal.js index 254ee8f415b..effce9de07e 100644 --- a/settings/js/personal.js +++ b/settings/js/personal.js @@ -258,23 +258,31 @@ $(document).ready(function () { }); federationSettingsView.render(); - $("#languageinput").change(function () { - // Serialize the data - var post = $("#languageinput").serialize(); - // Ajax foo - $.ajax( - 'ajax/setlanguage.php', - { - method: 'POST', - data: post + var updateLanguage = function () { + if (OC.PasswordConfirmation.requiresPasswordConfirmation()) { + OC.PasswordConfirmation.requirePasswordConfirmation(updateLanguage); + return; + } + + var selectedLang = $("#languageinput").val(), + user = OC.getCurrentUser(); + + $.ajax({ + url: OC.linkToOCS('cloud/users', 2) + user['uid'], + method: 'PUT', + data: { + key: 'language', + value: selectedLang + }, + success: function() { + location.reload(); + }, + fail: function() { + OC.Notification.showTemporary(t('settings', 'An error occured while changing your language. Please reload the page and try again.')); } - ).done(function() { - location.reload(); - }).fail(function(jqXHR) { - $('#passworderror').text(jqXHR.responseJSON.message); }); - return false; - }); + }; + $("#languageinput").change(updateLanguage); var uploadparms = { pasteZone: null, diff --git a/settings/personal.php b/settings/personal.php index fefd8392a10..fcccbc50556 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -73,62 +73,65 @@ $storageInfo=OC_Helper::getStorageInfo('/'); $user = OC::$server->getUserManager()->get(OC_User::getUser()); -$userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', \OC::$server->getL10NFactory()->findLanguage() ); -$languageCodes = \OC::$server->getL10NFactory()->findAvailableLanguages(); +$forceLanguage = $config->getSystemValue('force_language', false); +if ($forceLanguage === false) { + $userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', \OC::$server->getL10NFactory()->findLanguage() ); + $languageCodes = \OC::$server->getL10NFactory()->findAvailableLanguages(); + + // array of common languages + $commonLangCodes = array( + 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' + ); -// array of common languages -$commonLangCodes = array( - 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' -); + $languages=array(); + $commonLanguages = array(); + foreach($languageCodes as $lang) { + $l = \OC::$server->getL10N('settings', $lang); + // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version + $potentialName = (string) $l->t('__language_name__'); + if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file + $ln = array('code' => $lang, 'name' => $potentialName); + } elseif ($lang === 'en') { + $ln = ['code' => $lang, 'name' => 'English (US)']; + }else{//fallback to language code + $ln=array('code'=>$lang, 'name'=>$lang); + } -$languages=array(); -$commonLanguages = array(); -foreach($languageCodes as $lang) { - $l = \OC::$server->getL10N('settings', $lang); - // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version - $potentialName = (string) $l->t('__language_name__'); - if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file - $ln = array('code' => $lang, 'name' => $potentialName); - } elseif ($lang === 'en') { - $ln = ['code' => $lang, 'name' => 'English (US)']; - }else{//fallback to language code - $ln=array('code'=>$lang, 'name'=>$lang); + // put appropriate languages into appropriate arrays, to print them sorted + // used language -> common languages -> divider -> other languages + if ($lang === $userLang) { + $userLang = $ln; + } elseif (in_array($lang, $commonLangCodes)) { + $commonLanguages[array_search($lang, $commonLangCodes)]=$ln; + } else { + $languages[]=$ln; + } } - // put appropriate languages into appropriate arrays, to print them sorted - // used language -> common languages -> divider -> other languages - if ($lang === $userLang) { - $userLang = $ln; - } elseif (in_array($lang, $commonLangCodes)) { - $commonLanguages[array_search($lang, $commonLangCodes)]=$ln; - } else { - $languages[]=$ln; + // if user language is not available but set somehow: show the actual code as name + if (!is_array($userLang)) { + $userLang = [ + 'code' => $userLang, + 'name' => $userLang, + ]; } -} - -// if user language is not available but set somehow: show the actual code as name -if (!is_array($userLang)) { - $userLang = [ - 'code' => $userLang, - 'name' => $userLang, - ]; -} -ksort($commonLanguages); + ksort($commonLanguages); -// sort now by displayed language not the iso-code -usort( $languages, function ($a, $b) { - if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { - // If a doesn't have a name, but b does, list b before a - return 1; - } - if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { - // If a does have a name, but b doesn't, list a before b - return -1; - } - // Otherwise compare the names - return strcmp($a['name'], $b['name']); -}); + // sort now by displayed language not the iso-code + usort( $languages, function ($a, $b) { + if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { + // If a doesn't have a name, but b does, list b before a + return 1; + } + if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { + // If a does have a name, but b doesn't, list a before b + return -1; + } + // Otherwise compare the names + return strcmp($a['name'], $b['name']); + }); +} //links to clients $clients = array( @@ -165,9 +168,11 @@ $tmpl->assign('usage_relative', $storageInfo['relative']); $tmpl->assign('quota', $storageInfo['quota']); $tmpl->assign('clients', $clients); $tmpl->assign('email', $userData[\OC\Accounts\AccountManager::PROPERTY_EMAIL]['value']); -$tmpl->assign('languages', $languages); -$tmpl->assign('commonlanguages', $commonLanguages); -$tmpl->assign('activelanguage', $userLang); +if ($forceLanguage === false) { + $tmpl->assign('languages', $languages); + $tmpl->assign('commonlanguages', $commonLanguages); + $tmpl->assign('activelanguage', $userLang); +} $tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser())); $tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser())); $tmpl->assign('displayName', $userData[\OC\Accounts\AccountManager::PROPERTY_DISPLAYNAME]['value']); diff --git a/settings/routes.php b/settings/routes.php index fb85b11f390..048febaa129 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -69,7 +69,6 @@ $application->registerRoutes($this, [ ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], - ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], diff --git a/settings/templates/personal.php b/settings/templates/personal.php index dbc5b5611d5..7a7d87e930d 100644 --- a/settings/templates/personal.php +++ b/settings/templates/personal.php @@ -292,6 +292,7 @@ if($_['passwordChangeSupported']) { } ?> +<?php if (isset($_['activelanguage'])) { ?> <form id="language" class="section"> <h2> <label for="languageinput"><?php p($l->t('Language'));?></label> @@ -317,6 +318,7 @@ if($_['passwordChangeSupported']) { <em><?php p($l->t('Help translate'));?></em> </a> </form> +<?php } ?> <div id="clientsbox" class="section clientsbox"> |