adapt to force language changes
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
a596251d6b
commit
d881a3c37b
3 changed files with 41 additions and 22 deletions
|
@ -110,7 +110,7 @@ class PersonalInfo implements ISettings {
|
|||
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
|
||||
}
|
||||
|
||||
list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user);
|
||||
$languageParameters = $this->getLanguages($user);
|
||||
$messageParameters = $this->getMessageParameters($userData);
|
||||
|
||||
$parameters = [
|
||||
|
@ -139,10 +139,7 @@ class PersonalInfo implements ISettings {
|
|||
'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
|
||||
'groups' => $this->getGroups($user),
|
||||
'passwordChangeSupported' => \OC_User::canUserChangePassword($uid),
|
||||
'activelanguage' => $activeLanguage,
|
||||
'commonlanguages' => $commonLanguages,
|
||||
'languages' => $languages,
|
||||
] + $messageParameters;
|
||||
] + $messageParameters + $languageParameters;
|
||||
|
||||
|
||||
return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
|
||||
|
@ -194,11 +191,19 @@ class PersonalInfo implements ISettings {
|
|||
* @return array
|
||||
*/
|
||||
private function getLanguages(IUser $user) {
|
||||
$forceLanguage = $this->config->getSystemValue('force_language', false);
|
||||
if($forceLanguage !== false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$uid = $user->getUID();
|
||||
|
||||
$commonLanguages = [];
|
||||
$userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
|
||||
$languageCodes = $this->l10nFactory->findAvailableLanguages();
|
||||
|
||||
$commonLanguages = [];
|
||||
$languages = [];
|
||||
|
||||
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
|
||||
|
@ -246,7 +251,11 @@ class PersonalInfo implements ISettings {
|
|||
return strcmp($a['name'], $b['name']);
|
||||
});
|
||||
|
||||
return [$userLang, $commonLanguages, $languages];
|
||||
return [
|
||||
'activelanguage' => $userLang,
|
||||
'commonlanguages' => $commonLanguages,
|
||||
'languages' => $languages
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -259,23 +259,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,
|
||||
|
|
|
@ -287,6 +287,7 @@ if($_['passwordChangeSupported']) {
|
|||
}
|
||||
?>
|
||||
|
||||
<?php if (isset($_['activelanguage'])) { ?>
|
||||
<form id="language" class="section">
|
||||
<h2>
|
||||
<label for="languageinput"><?php p($l->t('Language'));?></label>
|
||||
|
@ -312,3 +313,4 @@ if($_['passwordChangeSupported']) {
|
|||
<em><?php p($l->t('Help translate'));?></em>
|
||||
</a>
|
||||
</form>
|
||||
<?php } ?>
|
||||
|
|
Loading…
Reference in a new issue