mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-23 20:34:40 +02:00
Update:More localization strings #1103
This commit is contained in:
parent
c1b3d7779b
commit
400e34a4c7
63 changed files with 681 additions and 584 deletions
|
@ -1,4 +1,5 @@
|
|||
import Vue from "vue"
|
||||
import enUsStrings from '../strings/en-us.json'
|
||||
|
||||
const defaultCode = 'en-us'
|
||||
|
||||
|
@ -13,7 +14,7 @@ function supplant(str, subs) {
|
|||
}
|
||||
|
||||
Vue.prototype.$i18nCode = ''
|
||||
Vue.prototype.$strings = {}
|
||||
Vue.prototype.$strings = enUsStrings
|
||||
Vue.prototype.$getString = (key, subs) => {
|
||||
if (!Vue.prototype.$strings[key]) return ''
|
||||
if (subs && Array.isArray(subs) && subs.length) {
|
||||
|
@ -22,7 +23,9 @@ Vue.prototype.$getString = (key, subs) => {
|
|||
return Vue.prototype.$strings[key]
|
||||
}
|
||||
|
||||
var translations = {}
|
||||
var translations = {
|
||||
[defaultCode]: enUsStrings
|
||||
}
|
||||
|
||||
function loadTranslationStrings(code) {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -30,7 +33,7 @@ function loadTranslationStrings(code) {
|
|||
resolve(fileContents.default)
|
||||
}).catch((error) => {
|
||||
console.error('Failed to load i18n strings', code, error)
|
||||
resolve({})
|
||||
resolve(null)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -40,19 +43,15 @@ async function loadi18n(code) {
|
|||
// already set
|
||||
return
|
||||
}
|
||||
|
||||
const currentCode = Vue.prototype.$i18nCode
|
||||
const strings = translations[code] || await loadTranslationStrings(code)
|
||||
if (!strings) {
|
||||
console.warn(`Invalid lang code ${code}`)
|
||||
return
|
||||
}
|
||||
|
||||
translations[code] = strings
|
||||
Vue.prototype.$i18nCode = code
|
||||
|
||||
if (!currentCode) {
|
||||
// first load
|
||||
Vue.prototype.$strings = strings
|
||||
return
|
||||
}
|
||||
|
||||
for (const key in Vue.prototype.$strings) {
|
||||
Vue.prototype.$strings[key] = strings[key] || translations[defaultCode][key]
|
||||
}
|
||||
|
@ -61,4 +60,7 @@ async function loadi18n(code) {
|
|||
|
||||
Vue.prototype.$i18nUpdate = loadi18n
|
||||
|
||||
loadi18n(defaultCode)
|
||||
const localLanguage = localStorage.getItem('lang')
|
||||
if (localLanguage !== defaultCode) {
|
||||
loadi18n(localLanguage)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue