Skip to content

Commit 8fa575c

Browse files
committed
Remake locale saving with Vue
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 257ab46 commit 8fa575c

15 files changed

Lines changed: 332 additions & 127 deletions

apps/settings/css/settings.css

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/settings/css/settings.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/settings/css/settings.scss

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ input {
117117
display: inline-grid;
118118
grid-template-columns: 1fr;
119119
grid-template-rows: 1fr 1fr 1fr 2fr;
120-
121-
#locale {
122-
h3 {
123-
height: 32px;
124-
}
125-
}
126120
}
127121

128122
.personal-show-container {
@@ -146,9 +140,7 @@ input {
146140
}
147141

148142
select {
149-
&#timezone,
150-
&#languageinput,
151-
&#localeinput {
143+
&#timezone {
152144
width: 100%;
153145
}
154146
}

apps/settings/js/settings/personalInfo.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -213,58 +213,6 @@ window.addEventListener('DOMContentLoaded', function () {
213213
});
214214
federationSettingsView.render();
215215

216-
var updateLanguage = function () {
217-
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
218-
OC.PasswordConfirmation.requirePasswordConfirmation(updateLanguage);
219-
return;
220-
}
221-
222-
var selectedLang = $("#languageinput").val(),
223-
user = OC.getCurrentUser();
224-
225-
$.ajax({
226-
url: OC.linkToOCS('cloud/users', 2) + user['uid'],
227-
method: 'PUT',
228-
data: {
229-
key: 'language',
230-
value: selectedLang
231-
},
232-
success: function() {
233-
location.reload();
234-
},
235-
fail: function() {
236-
OC.Notification.showTemporary(t('settings', 'An error occurred while changing your language. Please reload the page and try again.'));
237-
}
238-
});
239-
};
240-
$("#languageinput").change(updateLanguage);
241-
242-
var updateLocale = function () {
243-
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
244-
OC.PasswordConfirmation.requirePasswordConfirmation(updateLocale);
245-
return;
246-
}
247-
248-
var selectedLocale = $("#localeinput").val(),
249-
user = OC.getCurrentUser();
250-
251-
$.ajax({
252-
url: OC.linkToOCS('cloud/users', 2) + user.uid,
253-
method: 'PUT',
254-
data: {
255-
key: 'locale',
256-
value: selectedLocale
257-
},
258-
success: function() {
259-
moment.locale(selectedLocale);
260-
},
261-
fail: function() {
262-
OC.Notification.showTemporary(t('settings', 'An error occurred while changing your locale. Please reload the page and try again.'));
263-
}
264-
});
265-
};
266-
$("#localeinput").change(updateLocale);
267-
268216
var uploadparms = {
269217
pasteZone: null,
270218
done: function (e, data) {
@@ -385,10 +333,4 @@ window.addEventListener('DOMContentLoaded', function () {
385333
}, user.displayName);
386334
});
387335

388-
window.setInterval(function() {
389-
$('#localeexample-time').text(moment().format('LTS'))
390-
$('#localeexample-date').text(moment().format('L'))
391-
$('#localeexample-fdow').text(t('settings', 'Week starts on {fdow}', { fdow: dayNames[firstDay] }))
392-
}, 1000)
393-
394336
OC.Settings.updateAvatar = updateAvatar;

apps/settings/lib/Settings/Personal/PersonalInfo.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public function getForm(): TemplateResponse {
135135
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
136136
}
137137

138-
$localeParameters = $this->getLocales($user);
139138
$messageParameters = $this->getMessageParameters($account);
140139

141140
$parameters = [
@@ -157,14 +156,15 @@ public function getForm(): TemplateResponse {
157156
'groups' => $this->getGroups($user),
158157
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
159158
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
160-
] + $messageParameters + $localeParameters;
159+
] + $messageParameters;
161160

162161
$personalInfoParameters = [
163162
'userId' => $uid,
164163
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
165164
'twitter' => $this->getProperty($account, IAccountManager::PROPERTY_TWITTER),
166165
'emailMap' => $this->getEmailMap($account),
167166
'languageMap' => $this->getLanguageMap($user),
167+
'localeMap' => $this->getLocaleMap($user),
168168
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
169169
'profileEnabled' => $this->profileManager->isProfileEnabled($user),
170170
'organisation' => $this->getProperty($account, IAccountManager::PROPERTY_ORGANISATION),
@@ -319,31 +319,24 @@ private function getLanguageMap(IUser $user): array {
319319
);
320320
}
321321

322-
private function getLocales(IUser $user): array {
322+
private function getLocaleMap(IUser $user): array {
323323
$forceLanguage = $this->config->getSystemValue('force_locale', false);
324324
if ($forceLanguage !== false) {
325325
return [];
326326
}
327327

328328
$uid = $user->getUID();
329-
330329
$userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale());
331-
332330
$userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
333-
334331
$localeCodes = $this->l10nFactory->findAvailableLocales();
335-
336-
$userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) {
337-
return $userLocaleString === $value['code'];
338-
});
332+
$userLocale = array_filter($localeCodes, fn ($value) => $userLocaleString === $value['code']);
339333

340334
if (!empty($userLocale)) {
341335
$userLocale = reset($userLocale);
342336
}
343337

344-
$localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) {
345-
return 0 === strpos($localeCode['code'], $userLang);
346-
});
338+
$localesForLanguage = array_values(array_filter($localeCodes, fn ($localeCode) => strpos($localeCode['code'], $userLang) === 0));
339+
$otherLocales = array_values(array_filter($localeCodes, fn ($localeCode) => strpos($localeCode['code'], $userLang) !== 0));
347340

348341
if (!$userLocale) {
349342
$userLocale = [
@@ -353,10 +346,10 @@ private function getLocales(IUser $user): array {
353346
}
354347

355348
return [
356-
'activelocaleLang' => $userLocaleString,
357-
'activelocale' => $userLocale,
358-
'locales' => $localeCodes,
349+
'activeLocaleLang' => $userLocaleString,
350+
'activeLocale' => $userLocale,
359351
'localesForLanguage' => $localesForLanguage,
352+
'otherLocales' => $otherLocales,
360353
];
361354
}
362355

0 commit comments

Comments
 (0)