Add support for localized options

This commit is contained in:
printempw 2018-07-06 14:46:25 +08:00
parent 12b32fce3d
commit def8cc39b6
2 changed files with 16 additions and 9 deletions

View File

@ -317,13 +317,13 @@ class OptionForm
protected function getValueById($id) protected function getValueById($id)
{ {
if (false === ($result = $this->parseIdWithOffset($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 { } else {
$option = Arr::get( $option = Arr::get(
$this->values, $this->values,
$result['id'], $result['id'],
// Fallback to load from options // Fallback to load from options
@unserialize(option($result['id'])) @unserialize(option_localized($result['id']))
); );
return Arr::get($option, $result['offset']); return Arr::get($option, $result['offset']);
@ -628,7 +628,7 @@ class OptionFormGroup extends OptionFormItem
foreach ($this->items as $item) { foreach ($this->items as $item) {
if ($item['id'] && is_null($item['value'])) { 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([ $rendered[] = view('common.option-form.'.$item['type'])->with([

View File

@ -257,9 +257,10 @@ if (! function_exists('bs_custom_copyright')) {
function bs_custom_copyright() function bs_custom_copyright()
{ {
$localizedCopyrightText = option('copyright_text_'.config('app.locale'), option('copyright_text')); return Utils::getStringReplaced(option_localized('copyright_text'), [
'{site_name}' => option_localized('site_name'),
return Utils::getStringReplaced($localizedCopyrightText, ['{site_name}' => Option::get('site_name'), '{site_url}' => Option::get('site_url')]); '{site_url}' => option('site_url')
]);
} }
} }
@ -267,9 +268,7 @@ if (! function_exists('bs_announcement')) {
function bs_announcement() function bs_announcement()
{ {
$localizedAnnouncement = option('announcement_'.config('app.locale'), option('announcement')); return app('parsedown')->text(option_localized('announcement'));
return app('parsedown')->text($localizedAnnouncement);
} }
} }
@ -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')) { if (! function_exists('menv')) {
/** /**
* Gets the value of an environment variable by getenv() or $_ENV. * Gets the value of an environment variable by getenv() or $_ENV.