fix order of loading front-end l10n file

This commit is contained in:
Pig Fang 2021-02-18 09:43:23 +08:00
parent fa3a3a16cb
commit 97057bc432
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
4 changed files with 11 additions and 10 deletions

View File

@ -39,14 +39,10 @@ class FootComposer
public function injectJavaScript(View $view)
{
$scripts = [];
$locale = app()->getLocale();
$scripts[] = [
'src' => $this->javascript->generate($locale),
];
$scripts = $this->filter->apply('scripts', $scripts);
$view->with([
'i18n' => $this->javascript->generate(app()->getLocale()),
'scripts' => $scripts,
'inline_js' => option('custom_js'),
]);

View File

@ -1,15 +1,18 @@
interface I18nTable {
[key: string]: string | I18nTable | undefined
}
export function t(key: string, parameters = Object.create(null)): string {
const segments = key.split('.')
let temp = blessing.i18n as {
[k: string]: string | { [k: string]: string }
}
let temp = blessing.i18n as I18nTable | undefined
let result = ''
for (const segment of segments) {
if (!temp[segment]) {
/* istanbul ignore next */
const middle = temp?.[segment]
if (!middle) {
return key
}
const middle = temp[segment]
if (typeof middle === 'string') {
result = middle
} else {

View File

@ -9,5 +9,6 @@ test('translate text', () => {
expect(t('a.b.c')).toBe('text')
expect(t('a.b.d')).toBe('Hi, :name!')
expect(t('a.b.d', { name: 'me' })).toBe('Hi, me!')
expect(t('a.b.e')).toBe('a.b.e')
expect(t('d.e')).toBe('d.e')
})

View File

@ -1,4 +1,5 @@
<script src="https://cdn.jsdelivr.net/npm/@blessing-skin/admin-lte@3.0.5/dist/admin-lte.min.js" integrity="sha256-8RoBtV28TLYWlTMCRwqGv4NQW9bgc4jZphsQV3iLV4g=" crossorigin="anonymous"></script>
<script src="{{ i18n }}" crossorigin="anonymous"></script>
{{ include('assets.app', ignore_missing = true) }}
{% for script in scripts %}
<script{% for attribute, value in script %} {{ attribute }}="{{ value }}"{% endfor %}></script>