From 9e0aa328183bdfd938d4a4682c2367e26cf27e76 Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Wed, 14 Jan 2015 15:49:38 -0600 Subject: [PATCH] Added langs array and fix update lang message --- app/config/langs.php | 9 +++++++++ src/Composers/TimezoneLocaleComposer.php | 7 +++++-- src/Http/Controllers/DashSettingsController.php | 3 +++ src/Providers/LoadConfigServiceProvider.php | 16 ++++++++-------- 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 app/config/langs.php diff --git a/app/config/langs.php b/app/config/langs.php new file mode 100644 index 000000000..a7996cc26 --- /dev/null +++ b/app/config/langs.php @@ -0,0 +1,9 @@ + 'Deutsch', + 'en' => 'English', + 'fr' => 'Français', + 'pt-BR' => 'Portuguese, Brazilian', +]; diff --git a/src/Composers/TimezoneLocaleComposer.php b/src/Composers/TimezoneLocaleComposer.php index 2e0670d8a..a9ac5d916 100644 --- a/src/Composers/TimezoneLocaleComposer.php +++ b/src/Composers/TimezoneLocaleComposer.php @@ -4,6 +4,7 @@ namespace CachetHQ\Cachet\Composers; use DateTime; use DateTimeZone; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\View; class TimezoneLocaleComposer @@ -17,10 +18,12 @@ class TimezoneLocaleComposer */ public function compose(\Illuminate\View\View $view) { - $langs = array_map(function ($lang) { + $enabledLangs = Config::get('langs'); + + $langs = array_map(function ($lang) use ($enabledLangs) { $locale = basename($lang); - return [$locale => ucwords(locale_get_display_name($locale, $locale))]; + return [$locale => $enabledLangs[$locale]]; }, glob(app_path('lang').'/*')); $langs = call_user_func_array('array_merge', $langs); diff --git a/src/Http/Controllers/DashSettingsController.php b/src/Http/Controllers/DashSettingsController.php index 038f7d08f..190d1920e 100644 --- a/src/Http/Controllers/DashSettingsController.php +++ b/src/Http/Controllers/DashSettingsController.php @@ -6,6 +6,7 @@ use CachetHQ\Cachet\Models\Setting; use Exception; use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Routing\Controller; +use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\View; @@ -168,6 +169,8 @@ class DashSettingsController extends Controller return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure')); } + Lang::setLocale(Binput::get('app_locale')); + return Redirect::back()->with('success', trans('dashboard.settings.edit.success')); } } diff --git a/src/Providers/LoadConfigServiceProvider.php b/src/Providers/LoadConfigServiceProvider.php index d39b5396e..db4ad363f 100644 --- a/src/Providers/LoadConfigServiceProvider.php +++ b/src/Providers/LoadConfigServiceProvider.php @@ -3,9 +3,6 @@ namespace CachetHQ\Cachet\Providers; use CachetHQ\Cachet\Models\Setting; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Config; -use Illuminate\Support\Facades\Lang; use Illuminate\Support\ServiceProvider; class LoadConfigServiceProvider extends ServiceProvider @@ -17,15 +14,18 @@ class LoadConfigServiceProvider extends ServiceProvider */ public function boot() { - // + // Get app custom configuration. $appDomain = Setting::get('app_domain'); $appTimezone = Setting::get('app_timezone'); $appLocale = Setting::get('app_locale'); - Config::set('app.url', $appDomain ?: Config::get('app.url')); - Config::set('app.timezone', $appTimezone ?: Config::get('app.timezone')); - Config::set('app.locale', $appLocale ?: Config::get('app.locale')); - Lang::setLocale($appLocale); + // Override default app values. + $this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url')); + $this->app->config->set('app.timezone', $appTimezone ?: $this->app->config->get('app.timezone')); + $this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale')); + + // Set custom lang. + $this->app->translator->setLocale($appLocale); } /**