remade localization system once again

- new localization system: fast, dynamic, way more organized
- localization strings are WAY more descriptive
- it's now easier to add support for other languages (just one loc file instead of five)
- localization now falls back to english if localized string isnt available
- got rid of all static language selectors (probably)
- slightly updated english and russian strings
- miscellaneous settings items have been bundled together and moved to the bottom, cause they're used the least
- bottom links should no longer touch the popup border on overflow
- rearranged popup order in the rendered page
- bumped version up to 2.2.5

if you see strings that are like this: !!EXAMPLE!! or withoutspace please file an issue on github
This commit is contained in:
wukko
2022-07-24 16:54:05 +06:00
parent 8d275b0213
commit a4a9af6120
32 changed files with 339 additions and 299 deletions

View File

@@ -1,11 +1,11 @@
import loc from "./i18n.js";
import loc from "../../localization/manager.js";
export function internalError(res) {
res.status(501).json({ status: "error", text: "Internal Server Error" });
}
export function errorUnsupported(lang) {
return loc(lang, 'apiError', 'notSupported');
return loc(lang, 'ErrorUnsupported');
}
export function genericError(lang, host) {
return loc(lang, 'apiError', 'brokenLink', host);
return loc(lang, 'ErrorBrokenLink', host);
}

View File

@@ -1,18 +0,0 @@
import { supportedLanguages, appName, repo } from "../config.js";
import loadJson from "./loadJSON.js";
export default function(lang, cat, string, replacement) {
try {
if (!supportedLanguages.includes(lang)) lang = 'en';
let str = loadJson(`./src/i18n/${lang}/${cat}.json`);
if (str && str[string]) {
let s = str[string].replace(/\n/g, '<br/>').replace(/{appName}/g, appName).replace(/{repo}/g, repo)
if (replacement) s = s.replace(/{s}/g, replacement);
return s + ' '
} else {
return string
}
} catch (e) {
return string
}
}

View File

@@ -48,4 +48,7 @@ export function cleanURL(url, host) {
}
}
return url
}
export function languageCode(req) {
return req.header('Accept-Language') ? req.header('Accept-Language').slice(0, 2) : "en"
}