Allow fallback i18n

This commit is contained in:
Pig Fang 2019-03-30 15:04:55 +08:00
parent 867ef34628
commit e7f8503578
2 changed files with 14 additions and 15 deletions

View File

@ -12,8 +12,15 @@ async function loadI18n() {
{ lang: 'en', load: () => import('../../lang/en/front-end.yml') },
{ lang: 'zh_CN', load: () => import('../../lang/zh_CN/front-end.yml') },
]
const texts = await langs.find(({ lang }) => lang === blessing.locale).load()
blessing.i18n = Object.assign(blessing.i18n || Object.create(null), texts)
const texts = await langs.find(({ lang }) => lang === blessing.locale)
if (texts) {
blessing.i18n = Object.assign(blessing.i18n || Object.create(null), await texts.load())
} else {
blessing.i18n = Object.assign(
blessing.i18n || Object.create(null),
(await langs.find(({ lang }) => lang === blessing.fallback_locale)).load()
)
}
}
function loadModules() {

View File

@ -1,18 +1,10 @@
@if (file_exists(public_path($path = 'app/langs/'.config('app.locale').'.js')))
<script src="{{ url($path) }}"></script>
@if (file_exists(resource_path($path = 'lang/overrides/'.config('app.locale').'/locale.js')))
<script src="{{ url('resources/'.$path) }}"></script>
@endif
@else
<script src="{{ url('app/langs/'.config('app.fallback_locale').'.js') }}"></script>
@if (file_exists(resource_path($path = 'lang/overrides/'.config('app.fallback_locale').'/locale.js')))
<script src="{{ url('resources/'.$path) }}"></script>
@endif
@if (file_exists(resource_path($path = 'lang/overrides/'.config('app.locale').'/locale.js')))
<script src="{{ url('resources/'.$path) }}"></script>
@endif
@if (file_exists(resource_path($path = 'lang/overrides/'.config('app.fallback_locale').'/locale.js')))
<script src="{{ url('resources/'.$path) }}"></script>
@endif
<script src="{{ webpack_assets('index.js') }}"></script>
<!-- User custom scripts -->
<script>{!! option('custom_js') !!}</script>
{{-- Content added by plugins dynamically --}}
{!! bs_footer_extra() !!}