Store language select name in translation files (#10272)

* Move language selection string to translation files
Falls back to locale name

* Reload page for locale changes
This commit is contained in:
Tony Murray
2019-05-29 13:36:07 -05:00
committed by GitHub
parent 9455a83478
commit ea45fd9d42
4 changed files with 46 additions and 6 deletions

View File

@@ -64,12 +64,14 @@ class UserPreferencesController extends Controller
'default_dashboard' => UserPref::getPref($user, 'dashboard'),
'note_to_device' => UserPref::getPref($user, 'add_schedule_note_to_device'),
'locale' => UserPref::getPref($user, 'locale') ?: 'en',
'locales' => [
'en' => 'English',
'ru' => 'русский',
],
];
foreach (glob(resource_path('lang') . '/*', GLOB_ONLYDIR) as $locale) {
$locale = basename($locale);
$lang = __('preferences.lang', [], $locale);
$data['locales'][$locale] = ($lang == 'preferences.lang' ? $locale : $lang);
}
if (Config::get('twofactor')) {
$twofactor = UserPref::getPref($user, 'twofactor');
if ($twofactor) {

View File

@@ -0,0 +1,17 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| User preferences
|--------------------------------------------------------------------------
|
| Translation strings for user preferences
| lang: is the display name for this language in the language select dialog
|
*/
'lang' => 'English',
];

View File

@@ -0,0 +1,17 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| User preferences
|--------------------------------------------------------------------------
|
| Translation strings for user preferences
| lang: is the display name for this language in the language select dialog
|
*/
'lang' => 'русский',
];

View File

@@ -200,16 +200,20 @@
$('.ajax-select').change(function () {
var $this = $(this);
var value = $this.val();
console.log($this.data('pref'));
var pref = $this.data('pref');
$.ajax({
url: '{{ route('preferences.store') }}',
dataType: 'json',
type: 'POST',
data: {
pref: $this.data('pref'),
pref: pref,
value: value
},
success: function () {
if (pref === 'locale') {
location.reload();
}
$this.data('previous', value);
$this.closest('.form-group').addClass('has-success');
setTimeout(function () {