mirror of
https://github.com/openvk/openvk
synced 2024-12-24 01:21:07 +03:00
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
|
function tr(string, ...arg) {
|
||
|
let output = window.lang[string];
|
||
|
if(arg.length > 0) {
|
||
|
if(typeof arg[0] == 'number') {
|
||
|
let numberedStringId;
|
||
|
let cardinal = arg[0];
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let i = 1;
|
||
|
arg.forEach(element => {
|
||
|
output = output.replace(RegExp('(\\$' + i + ')'), element);
|
||
|
i++;
|
||
|
});
|
||
|
return output;
|
||
|
}
|