fix order of loading front-end l10n file
This commit is contained in:
parent
fa3a3a16cb
commit
97057bc432
|
|
@ -39,14 +39,10 @@ class FootComposer
|
||||||
public function injectJavaScript(View $view)
|
public function injectJavaScript(View $view)
|
||||||
{
|
{
|
||||||
$scripts = [];
|
$scripts = [];
|
||||||
|
|
||||||
$locale = app()->getLocale();
|
|
||||||
$scripts[] = [
|
|
||||||
'src' => $this->javascript->generate($locale),
|
|
||||||
];
|
|
||||||
$scripts = $this->filter->apply('scripts', $scripts);
|
$scripts = $this->filter->apply('scripts', $scripts);
|
||||||
|
|
||||||
$view->with([
|
$view->with([
|
||||||
|
'i18n' => $this->javascript->generate(app()->getLocale()),
|
||||||
'scripts' => $scripts,
|
'scripts' => $scripts,
|
||||||
'inline_js' => option('custom_js'),
|
'inline_js' => option('custom_js'),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
|
interface I18nTable {
|
||||||
|
[key: string]: string | I18nTable | undefined
|
||||||
|
}
|
||||||
|
|
||||||
export function t(key: string, parameters = Object.create(null)): string {
|
export function t(key: string, parameters = Object.create(null)): string {
|
||||||
const segments = key.split('.')
|
const segments = key.split('.')
|
||||||
let temp = blessing.i18n as {
|
let temp = blessing.i18n as I18nTable | undefined
|
||||||
[k: string]: string | { [k: string]: string }
|
|
||||||
}
|
|
||||||
let result = ''
|
let result = ''
|
||||||
|
|
||||||
for (const segment of segments) {
|
for (const segment of segments) {
|
||||||
if (!temp[segment]) {
|
/* istanbul ignore next */
|
||||||
|
const middle = temp?.[segment]
|
||||||
|
if (!middle) {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
const middle = temp[segment]
|
|
||||||
if (typeof middle === 'string') {
|
if (typeof middle === 'string') {
|
||||||
result = middle
|
result = middle
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,6 @@ test('translate text', () => {
|
||||||
expect(t('a.b.c')).toBe('text')
|
expect(t('a.b.c')).toBe('text')
|
||||||
expect(t('a.b.d')).toBe('Hi, :name!')
|
expect(t('a.b.d')).toBe('Hi, :name!')
|
||||||
expect(t('a.b.d', { name: 'me' })).toBe('Hi, me!')
|
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')
|
expect(t('d.e')).toBe('d.e')
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -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="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) }}
|
{{ include('assets.app', ignore_missing = true) }}
|
||||||
{% for script in scripts %}
|
{% for script in scripts %}
|
||||||
<script{% for attribute, value in script %} {{ attribute }}="{{ value }}"{% endfor %}></script>
|
<script{% for attribute, value in script %} {{ attribute }}="{{ value }}"{% endfor %}></script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user