mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-15 13:51:35 +00:00
Removed duplicate strings and added English fallback
This commit is contained in:
parent
d3a55c8b1a
commit
d72665a648
19 changed files with 106 additions and 2131 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import Vue from "vue"
|
||||
import enUsStrings from '../strings/en-us.json'
|
||||
import enUsStrings from '../strings/en-us/strings.json'
|
||||
import { supplant } from './utils'
|
||||
|
||||
const defaultCode = 'en-us'
|
||||
|
|
@ -40,7 +40,7 @@ Vue.prototype.$strings = { ...enUsStrings }
|
|||
Vue.prototype.$getString = (key, subs) => {
|
||||
if (!Vue.prototype.$strings[key]) return ''
|
||||
if (subs?.length && Array.isArray(subs)) {
|
||||
return supplant(Vue.prototype.$strings[key], subs)
|
||||
return supplant(Vue.prototype.$strings[key], subs, enUsStrings)
|
||||
}
|
||||
return Vue.prototype.$strings[key]
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ var translations = {
|
|||
|
||||
function loadTranslationStrings(code) {
|
||||
return new Promise((resolve) => {
|
||||
import(`../strings/${code}`).then((fileContents) => {
|
||||
import(`../strings/${code}/strings`).then((fileContents) => {
|
||||
resolve(fileContents.default)
|
||||
}).catch((error) => {
|
||||
console.error('Failed to load i18n strings', code, error)
|
||||
|
|
|
|||
|
|
@ -169,11 +169,11 @@ Vue.prototype.$downloadFile = (url, filename = null, openInNewTab = false) => {
|
|||
})
|
||||
}
|
||||
|
||||
export function supplant(str, subs) {
|
||||
export function supplant(str, subs, defaultMapping) {
|
||||
// source: http://crockford.com/javascript/remedial.html
|
||||
return str.replace(/{([^{}]*)}/g,
|
||||
function (a, b) {
|
||||
var r = subs[b]
|
||||
var r = subs[b] || (defaultMapping && defaultMapping[b]);
|
||||
return typeof r === 'string' || typeof r === 'number' ? r : a
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue