mirror of https://github.com/hrfee/jfa-go
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
4 years ago
|
interface Meta {
|
||
|
name: string;
|
||
|
}
|
||
|
|
||
|
interface quantityString {
|
||
|
singular: string;
|
||
|
plural: string;
|
||
|
}
|
||
|
|
||
|
export interface LangFile {
|
||
|
meta: Meta;
|
||
|
strings: { [key: string]: string };
|
||
|
notifications: { [key: string]: string };
|
||
|
quantityStrings: { [key: string]: quantityString };
|
||
|
}
|
||
|
|
||
|
export class lang implements Lang {
|
||
|
private _lang: LangFile;
|
||
|
constructor(lang: LangFile) {
|
||
|
this._lang = lang;
|
||
|
}
|
||
|
|
||
|
get = (sect: string, key: string): string => {
|
||
|
if (sect == "quantityStrings" || sect == "meta") { return ""; }
|
||
|
return this._lang[sect][key];
|
||
|
}
|
||
|
|
||
|
strings = (key: string): string => this.get("strings", key)
|
||
|
notif = (key: string): string => this.get("notifications", key)
|
||
|
|
||
|
var = (sect: string, key: string, ...subs: string[]): string => {
|
||
|
if (sect == "quantityStrings" || sect == "meta") { return ""; }
|
||
|
let str = this._lang[sect][key];
|
||
|
for (let sub of subs) {
|
||
|
str = str.replace("{n}", sub);
|
||
|
}
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
quantity = (key: string, number: number): string => {
|
||
|
if (number == 1) {
|
||
|
return this._lang.quantityStrings[key].singular.replace("{n}", ""+number)
|
||
|
}
|
||
|
return this._lang.quantityStrings[key].plural.replace("{n}", ""+number);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|