Skip to content

Commit c871ba3

Browse files
authored
Adding fallback_locale
just add next to your layout: <meta name="fallback_locale" content="{{ config('app.fallback_locale') }}">
1 parent 3e958cf commit c871ba3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/resources/js/VueTranslation/Translation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ export default {
33
translate(key,replacements={}) {
44
let lang = document.documentElement.lang;
55
let word = translations[lang];
6+
let fallback_locale = document.querySelector('meta[name="fallback_locale"]') || null;
7+
68
const keys = key.split('.');
79
for (let i in keys) {
810
try {
911
word = word[keys[i]];
1012
if (word === undefined) {
11-
word = key;
13+
if (fallback_locale.content){
14+
word = translations[fallback_locale.content][keys[i]];
15+
} else {
16+
word = key;
17+
}
1218
break;
1319
}
1420
} catch (e) {

0 commit comments

Comments
 (0)