mirror of
https://github.com/openvk/openvk
synced 2024-12-25 18:11:07 +03:00
37 lines
1.1 KiB
JavaScript
Executable file
37 lines
1.1 KiB
JavaScript
Executable file
function tr(string, ...args) {
|
|
let output = window.lang[string];
|
|
if(args.length > 0) {
|
|
if(typeof args[0] === "number") {
|
|
const cardinal = args[0];
|
|
let numberedString;
|
|
|
|
switch(cardinal) {
|
|
case 0:
|
|
numberedString = string + "_zero";
|
|
break;
|
|
case 1:
|
|
numberedString = string + "_one";
|
|
break;
|
|
default:
|
|
numberedString = string + (cardinal < 5 ? "_few" : "_other");
|
|
}
|
|
|
|
let newOutput = window.lang[numberedString];
|
|
if(newOutput == null)
|
|
newOutput = window.lang[string + "_other"];
|
|
|
|
if(newOutput == null)
|
|
newOutput = output;
|
|
|
|
output = newOutput;
|
|
}
|
|
}
|
|
|
|
if(output == null)
|
|
return "@" + string;
|
|
|
|
for(const [ i, element ] of Object.entries(args))
|
|
output = output.replace(RegExp("(\\$" + (Number(i) + 1) + ")"), element);
|
|
|
|
return output;
|
|
}
|