2020-07-20 22:07:04 +00:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
2020-11-06 00:58:26 +00:00
|
|
|
import AllTranslationAssets from "../../AllTranslationAssets";
|
|
|
|
import {Translation} from "./Translation";
|
2020-10-28 10:19:47 +00:00
|
|
|
|
2020-07-20 10:39:43 +00:00
|
|
|
export default class Translations {
|
2020-07-21 21:31:41 +00:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
throw "Translations is static. If you want to intitialize a new translation, use the singular form"
|
|
|
|
}
|
|
|
|
|
2020-11-06 00:58:26 +00:00
|
|
|
static t = AllTranslationAssets.t;
|
2020-07-20 22:38:03 +00:00
|
|
|
public static W(s: string | UIElement): UIElement {
|
2020-08-22 00:12:46 +00:00
|
|
|
if (typeof (s) === "string") {
|
|
|
|
return new FixedUiElement(s);
|
2020-07-20 10:39:43 +00:00
|
|
|
}
|
2020-08-22 00:12:46 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2020-10-27 00:01:34 +00:00
|
|
|
|
|
|
|
static T(t: string | any): Translation {
|
|
|
|
if(t === undefined){
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
if(typeof t === "string"){
|
|
|
|
return new Translation({"*":t});
|
|
|
|
}
|
|
|
|
if(t.render !== undefined){
|
|
|
|
const msg = "Creating a translation, but this object contains a 'render'-field. Use the translation directly"
|
|
|
|
console.error(msg, t);
|
|
|
|
throw msg
|
|
|
|
}
|
|
|
|
return new Translation(t);
|
|
|
|
}
|
|
|
|
|
2020-10-14 10:15:09 +00:00
|
|
|
private static wtcache = {}
|
2020-08-22 00:12:46 +00:00
|
|
|
public static WT(s: string | Translation): Translation {
|
2020-10-11 23:25:27 +00:00
|
|
|
if(s === undefined){
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-08-22 00:12:46 +00:00
|
|
|
if (typeof (s) === "string") {
|
2020-10-14 10:15:09 +00:00
|
|
|
if(Translations.wtcache[s]){
|
|
|
|
return Translations.wtcache[s];
|
|
|
|
}
|
|
|
|
const tr = new Translation({en: s});
|
|
|
|
Translations.wtcache[s]= tr;
|
|
|
|
return tr;
|
2020-08-22 00:12:46 +00:00
|
|
|
}
|
2020-10-09 18:10:21 +00:00
|
|
|
if (s instanceof Translation) {
|
|
|
|
return s;
|
|
|
|
}
|
2020-10-10 12:09:12 +00:00
|
|
|
console.error("Trying to Translation.WT, but got ",s)
|
2020-10-09 18:10:21 +00:00
|
|
|
throw "??? Not a valid translation"
|
2020-07-20 10:39:43 +00:00
|
|
|
}
|
2020-07-20 22:07:04 +00:00
|
|
|
|
2020-07-26 00:01:34 +00:00
|
|
|
public static CountTranslations() {
|
|
|
|
const queue: any = [Translations.t];
|
|
|
|
const tr: Translation[] = [];
|
|
|
|
while (queue.length > 0) {
|
|
|
|
const item = queue.pop();
|
|
|
|
if (item instanceof Translation || item.translations !== undefined) {
|
|
|
|
tr.push(item);
|
2020-07-31 15:38:03 +00:00
|
|
|
} else if (typeof (item) === "string") {
|
|
|
|
console.warn("Got single string in translationgs file: ", item);
|
2020-07-26 00:01:34 +00:00
|
|
|
} else {
|
|
|
|
for (const t in item) {
|
|
|
|
const x = item[t];
|
|
|
|
queue.push(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const langaugeCounts = {};
|
|
|
|
for (const translation of tr) {
|
|
|
|
for (const language in translation.translations) {
|
|
|
|
if (langaugeCounts[language] === undefined) {
|
|
|
|
langaugeCounts[language] = 1
|
|
|
|
} else {
|
|
|
|
langaugeCounts[language]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const language in langaugeCounts) {
|
|
|
|
console.log("Total translations in ", language, langaugeCounts[language], "/", tr.length)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-15 16:44:58 +00:00
|
|
|
}
|