Skip to content

Commit

Permalink
Add ability to change the user language (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kovah committed Oct 9, 2020
1 parent c43867c commit c6bec43
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
4 changes: 4 additions & 0 deletions app/Http/Middleware/SettingsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function handle($request, Closure $next)
config(['app.timezone' => $user_timezone]);
}

if ($userLocale = usersettings('locale')) {
app()->setLocale($userLocale);
}

return $next($request);
}
}
1 change: 1 addition & 0 deletions app/Http/Requests/UserSettingsUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function authorize(Request $request)
public function rules()
{
return [
'locale' => 'required',
'timezone' => 'required',
];
}
Expand Down
6 changes: 6 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@

'locale' => 'en_US',

'available_locales' => [
'en_US' => 'English',
'de_DE' => 'Deutsch',
'zh_CN' => '简体中文',
],

/*
|--------------------------------------------------------------------------
| Application Fallback Locale
Expand Down
1 change: 1 addition & 0 deletions resources/lang/de_DE/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'app_settings' => 'Anwendungseinstellungen',
'system_settings' => 'Systemeinstellungen',

'language' => 'Sprache',
'timezone' => 'Zeitzone',
'date_format' => 'Datumsformat',
'time_format' => 'Zeitformat',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en_US/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'app_settings' => 'Application Settings',
'system_settings' => 'System Settings',

'language' => 'Language',
'timezone' => 'Timezone',
'date_format' => 'Date Format',
'time_format' => 'Time Format',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/zh_CN/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'app_settings' => '应用程序设置',
'system_settings' => '系统设置',

'language' => '语言',
'timezone' => '时区',
'date_format' => '日期格式',
'time_format' => '时间格式',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
<div class="col-12 col-sm-8 col-md-6">

<div class="form-group">
<label for="timezone">
@lang('settings.timezone')
<label for="locale">
@lang('settings.language')
</label>
<select id="timezone" name="timezone"
class="simple-select {{ $errors->has('timezone') ? ' is-invalid' : '' }}">
@foreach(timezone_identifiers_list() as $key => $zone)
<option value="{{ $zone }}"
@if($user->settings()->get('timezone') === $zone) selected @endif>
{{ $zone }}
<select id="locale" name="locale"
class="simple-select {{ $errors->has('locale') ? ' is-invalid' : '' }}">
@foreach(config('app.available_locales') as $key => $locale)
<option value="{{ $key }}"
@if($user->settings()->get('locale') === $key) selected @endif>
{{ $locale }}
</option>
@endforeach
</select>
@if ($errors->has('timezone'))
@if ($errors->has('locale'))
<p class="invalid-feedback" role="alert">
{{ $errors->first('timezone') }}
{{ $errors->first('locale') }}
</p>
@endif
</div>
Expand All @@ -34,21 +34,21 @@ class="simple-select {{ $errors->has('timezone') ? ' is-invalid' : '' }}">
<div class="col-12 col-sm-8 col-md-6">

<div class="form-group">
<label for="links_new_tab">
@lang('settings.links_new_tab')
<label for="timezone">
@lang('settings.timezone')
</label>
<select id="links_new_tab" name="links_new_tab"
class="simple-select {{ $errors->has('links_new_tab') ? ' is-invalid' : '' }}">
<option value="0" @if($user->settings()->get('links_new_tab') === '0') selected @endif>
@lang('linkace.no')
</option>
<option value="1" @if($user->settings()->get('links_new_tab') === '1') selected @endif>
@lang('linkace.yes')
</option>
<select id="timezone" name="timezone"
class="simple-select {{ $errors->has('timezone') ? ' is-invalid' : '' }}">
@foreach(timezone_identifiers_list() as $key => $zone)
<option value="{{ $zone }}"
@if($user->settings()->get('timezone') === $zone) selected @endif>
{{ $zone }}
</option>
@endforeach
</select>
@if ($errors->has('links_new_tab'))
@if ($errors->has('timezone'))
<p class="invalid-feedback" role="alert">
{{ $errors->first('links_new_tab') }}
{{ $errors->first('timezone') }}
</p>
@endif
</div>
Expand Down Expand Up @@ -105,7 +105,7 @@ class="custom-select{{ $errors->has('time_format') ? ' is-invalid' : '' }}">
</div>
</div>

<div class="row">
<div class="row mt-4">
<div class="col-12 col-sm-8 col-md-6">

<div class="form-group">
Expand Down Expand Up @@ -166,6 +166,33 @@ class="custom-select{{ $errors->has('link_display_mode') ? ' is-invalid' : '' }}
</div>
</div>

<div class="row">
<div class="col-12 col-sm-8 col-md-6">

<div class="form-group">
<label for="links_new_tab">
@lang('settings.links_new_tab')
</label>
<select id="links_new_tab" name="links_new_tab"
class="simple-select {{ $errors->has('links_new_tab') ? ' is-invalid' : '' }}">
<option value="0" @if($user->settings()->get('links_new_tab') === '0') selected @endif>
@lang('linkace.no')
</option>
<option value="1" @if($user->settings()->get('links_new_tab') === '1') selected @endif>
@lang('linkace.yes')
</option>
</select>
@if ($errors->has('links_new_tab'))
<p class="invalid-feedback" role="alert">
{{ $errors->first('links_new_tab') }}
</p>
@endif
</div>

</div>
<div class="col-12 col-sm-8 col-md-6"></div>
</div>

@include('actions.settings.partials.user.app-settings.archive-backups')

@include('actions.settings.partials.user.app-settings.privacy')
Expand Down

0 comments on commit c6bec43

Please sign in to comment.