From def8cc39b6211efba323df205f3bae3a98efdc1b Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 6 Jul 2018 14:46:25 +0800 Subject: [PATCH] Add support for localized options --- app/Services/OptionForm.php | 6 +++--- app/helpers.php | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/Services/OptionForm.php b/app/Services/OptionForm.php index 2eb1b685..2703dfa2 100644 --- a/app/Services/OptionForm.php +++ b/app/Services/OptionForm.php @@ -317,13 +317,13 @@ class OptionForm protected function getValueById($id) { if (false === ($result = $this->parseIdWithOffset($id))) { - return Arr::get($this->values, $id, option($id)); + return Arr::get($this->values, $id, option_localized($id)); } else { $option = Arr::get( $this->values, $result['id'], // Fallback to load from options - @unserialize(option($result['id'])) + @unserialize(option_localized($result['id'])) ); return Arr::get($option, $result['offset']); @@ -628,7 +628,7 @@ class OptionFormGroup extends OptionFormItem foreach ($this->items as $item) { if ($item['id'] && is_null($item['value'])) { - $item['value'] = option($item['id']); + $item['value'] = option_localized($item['id']); } $rendered[] = view('common.option-form.'.$item['type'])->with([ diff --git a/app/helpers.php b/app/helpers.php index 9840f3c8..adbcdc71 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -257,9 +257,10 @@ if (! function_exists('bs_custom_copyright')) { function bs_custom_copyright() { - $localizedCopyrightText = option('copyright_text_'.config('app.locale'), option('copyright_text')); - - return Utils::getStringReplaced($localizedCopyrightText, ['{site_name}' => Option::get('site_name'), '{site_url}' => Option::get('site_url')]); + return Utils::getStringReplaced(option_localized('copyright_text'), [ + '{site_name}' => option_localized('site_name'), + '{site_url}' => option('site_url') + ]); } } @@ -267,9 +268,7 @@ if (! function_exists('bs_announcement')) { function bs_announcement() { - $localizedAnnouncement = option('announcement_'.config('app.locale'), option('announcement')); - - return app('parsedown')->text($localizedAnnouncement); + return app('parsedown')->text(option_localized('announcement')); } } @@ -332,6 +331,14 @@ if (! function_exists('option')) { } } +if (! function_exists('option_localized')) { + + function option_localized($key = null, $default = null, $raw = false) + { + return option($key.'_'.config('app.locale'), option($key)); + } +} + if (! function_exists('menv')) { /** * Gets the value of an environment variable by getenv() or $_ENV.