akkoma-fe/src/i18n/messages.js

59 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2018-09-09 15:54:23 +00:00
// When contributing, please sort JSON before committing so it would be easier to see what's missing and what's being added compared to English and other languages. It's not obligatory, but just an advice.
// To sort json use jq https://stedolan.github.io/jq and invoke it like `jq -S . xx.json > xx.sorted.json`, AFAIK, there's no inplace edit option like in sed
// Also, when adding a new language to "messages" variable, please do it alphabetically by language code so that users can search or check their custom language easily.
2018-09-09 15:54:23 +00:00
// For anyone contributing to old huge messages.js and in need to quickly convert it to JSON
2018-09-06 16:39:56 +00:00
// sed command for converting currently formatted JS to JSON:
// sed -i -e "s/'//gm" -e 's/"/\\"/gm' -re 's/^( +)(.+?): ((.+?))?(,?)(\{?)$/\1"\2": "\4"/gm' -e 's/\"\{\"/{/g' -e 's/,"$/",/g' file.json
2018-09-09 15:54:23 +00:00
// There's only problem that apostrophe character ' gets replaced by \\ so you have to fix it manually, sorry.
2017-11-11 04:21:49 +00:00
const loaders = {
ar: () => import('./ar.json'),
ca: () => import('./ca.json'),
cs: () => import('./cs.json'),
de: () => import('./de.json'),
eo: () => import('./eo.json'),
es: () => import('./es.json'),
et: () => import('./et.json'),
eu: () => import('./eu.json'),
fi: () => import('./fi.json'),
fr: () => import('./fr.json'),
ga: () => import('./ga.json'),
he: () => import('./he.json'),
hu: () => import('./hu.json'),
id: () => import('./id.json'),
it: () => import('./it.json'),
ja: () => import('./ja_pedantic.json'),
ja_easy: () => import('./ja_easy.json'),
ko: () => import('./ko.json'),
nb: () => import('./nb.json'),
nl: () => import('./nl.json'),
oc: () => import('./oc.json'),
pl: () => import('./pl.json'),
pt: () => import('./pt.json'),
ro: () => import('./ro.json'),
ru: () => import('./ru.json'),
sk: () => import('./sk.json'),
2022-04-06 15:43:47 +00:00
te: () => import('./te.json'),
2020-12-14 19:52:07 +00:00
uk: () => import('./uk.json'),
2023-10-02 12:28:23 +00:00
vi: () => import('./vi.json'),
zh: () => import('./zh.json'),
zh_Hant: () => import('./zh_Hant.json')
}
2017-11-07 14:14:37 +00:00
const messages = {
2020-06-09 07:26:46 +00:00
languages: ['en', ...Object.keys(loaders)],
default: {
2022-04-06 12:45:44 +00:00
en: require('./en.json').default
},
setLanguage: async (i18n, language) => {
if (loaders[language]) {
let messages = await loaders[language]()
2022-04-06 12:45:44 +00:00
i18n.setLocaleMessage(language, messages.default)
}
i18n.locale = language
}
2017-11-07 14:14:37 +00:00
}
export default messages