cobalt/modules/sub/loc.js

23 lines
677 B
JavaScript
Raw Normal View History

import { supportedLanguages, appName, repo } from "../config.js";
2022-07-08 19:17:56 +01:00
import loadJson from "./load-json.js";
export default function(lang, cat, string, replacement) {
if (!supportedLanguages.includes(lang)) {
2022-07-08 19:17:56 +01:00
lang = 'en'
}
try {
let str = loadJson(`./strings/${lang}/${cat}.json`);
if (str && str[string]) {
let s = str[string].replace(/\n/g, '<br/>').replace(/{appName}/g, appName).replace(/{repo}/g, repo)
2022-07-08 19:17:56 +01:00
if (replacement) {
s = s.replace(/{s}/g, replacement)
}
return s + ' '
} else {
return string
}
} catch (e) {
return string
}
}