2021-12-22 20:09:05 +03:00
|
|
|
function tr(string, ...args) {
|
2021-12-04 16:06:28 +03:00
|
|
|
let output = window.lang[string];
|
2021-12-22 20:09:05 +03:00
|
|
|
if(args.length > 0) {
|
|
|
|
if(typeof args[0] === "number") {
|
|
|
|
const cardinal = args[0];
|
|
|
|
let numberedString;
|
|
|
|
|
2021-12-04 16:06:28 +03:00
|
|
|
switch(cardinal) {
|
|
|
|
case 0:
|
2021-12-22 20:09:05 +03:00
|
|
|
numberedString = string + "_zero";
|
2021-12-04 16:06:28 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-12-22 20:09:05 +03:00
|
|
|
numberedString = string + "_one";
|
2021-12-04 16:06:28 +03:00
|
|
|
break;
|
|
|
|
default:
|
2021-12-22 20:09:05 +03:00
|
|
|
numberedString = string + (cardinal < 5 ? "_few" : "_other");
|
2021-12-04 16:06:28 +03:00
|
|
|
}
|
|
|
|
|
2021-12-22 20:09:05 +03:00
|
|
|
let newOutput = window.lang[numberedString];
|
2021-12-24 23:58:36 +03:00
|
|
|
if(newOutput == null)
|
2021-12-22 20:09:05 +03:00
|
|
|
newOutput = window.lang[string + "_other"];
|
|
|
|
|
2021-12-24 23:58:36 +03:00
|
|
|
if(newOutput == null)
|
2021-12-22 20:09:05 +03:00
|
|
|
newOutput = output;
|
2021-12-04 16:06:28 +03:00
|
|
|
|
2021-12-22 20:09:05 +03:00
|
|
|
output = newOutput;
|
2021-12-04 16:06:28 +03:00
|
|
|
}
|
|
|
|
}
|
2021-12-22 20:09:05 +03:00
|
|
|
|
|
|
|
if(output == null)
|
|
|
|
return "@" + string;
|
|
|
|
|
|
|
|
for(const [ i, element ] of Object.entries(args))
|
|
|
|
output = output.replace(RegExp("(\\$" + (Number(i) + 1) + ")"), element);
|
|
|
|
|
2021-12-04 16:06:28 +03:00
|
|
|
return output;
|
2021-12-22 20:09:05 +03:00
|
|
|
}
|