+ Перевод текста на клиенте, функция: trts
This commit is contained in:
@ -20,6 +20,35 @@ function trt(key)
|
||||
else return val;
|
||||
}
|
||||
|
||||
function trts(text)
|
||||
{
|
||||
let result='';
|
||||
let pLen=4; //Длина преамбулы trt(
|
||||
let cut=0;
|
||||
let from = 0; // Позиция поиска для итерации
|
||||
while (true)
|
||||
{
|
||||
let pos1 = text.indexOf('trt(', from);
|
||||
if(pos1 >= 0)
|
||||
{
|
||||
from = pos1+pLen+1;
|
||||
let pos2 = -1;
|
||||
if(text[pos1+pLen] == '"') pos2 = text.indexOf('")', from);
|
||||
if(text[pos1+pLen] == "'") pos2 = text.indexOf("')", from);
|
||||
if(pos2 > 0)
|
||||
{
|
||||
result+=text.substring(cut, pos1);
|
||||
let toTranslate=text.substring(pos1+pLen+1, pos2 );
|
||||
result+=trt(toTranslate);
|
||||
cut=pos2+2;
|
||||
from = pos2;
|
||||
}
|
||||
}else break;
|
||||
}
|
||||
result+=text.substring(cut); //Копируем остатки
|
||||
return result;
|
||||
}
|
||||
|
||||
function deleteOption(sel,id){
|
||||
if(typeof sel == 'string') sel=document.getElementById(sel);
|
||||
let i=0;
|
||||
@ -1680,7 +1709,7 @@ class TWin
|
||||
//Подгрузить содержимое окна из указаного места
|
||||
//json - объект который передастца в виде JSON строки по URL
|
||||
//func - функция которая выполниться после загрузки данных в форму
|
||||
load(url,json,func)
|
||||
load(url,json,func,tr)
|
||||
{
|
||||
this.showProgressBar();
|
||||
var r=createRequestObject();
|
||||
@ -1688,7 +1717,8 @@ class TWin
|
||||
{
|
||||
return function(){
|
||||
if(r.readyState == 4){
|
||||
w.innerHTML=r.responseText;
|
||||
if(tr) w.innerHTML=trts(r.responseText);
|
||||
else w.innerHTML=r.responseText;
|
||||
thiz.hideProgressBar();
|
||||
if(func !== undefined && func!=null) func();
|
||||
|
||||
@ -1699,7 +1729,7 @@ class TWin
|
||||
thiz.setCenter();
|
||||
}
|
||||
}
|
||||
}(r,this.co,this,func)
|
||||
}(r,this.co,this,func,tr)
|
||||
r.open( "POST", url, true );
|
||||
if(json!=null)
|
||||
r.send(JSON.stringify(json));
|
||||
|
||||
Reference in New Issue
Block a user