Removed duplicate strings and added English fallback

This commit is contained in:
Nicholas 2023-11-10 15:50:05 -07:00
parent d3a55c8b1a
commit d72665a648
19 changed files with 106 additions and 2131 deletions

View file

@ -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)

View file

@ -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
}
)