Partly integrate plural translations into js
This commit is contained in:
parent
560839195e
commit
4e214883d6
|
@ -28,9 +28,11 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log ==
|
||||||
* translate a string
|
* translate a string
|
||||||
* @param app the id of the app for which to translate the string
|
* @param app the id of the app for which to translate the string
|
||||||
* @param text the string to translate
|
* @param text the string to translate
|
||||||
|
* @param vars (optional) FIXME
|
||||||
|
* @param count (optional) number to replace %n with
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function t(app,text, vars){
|
function t(app, text, vars, count){
|
||||||
if( !( t.cache[app] )){
|
if( !( t.cache[app] )){
|
||||||
$.ajax(OC.filePath('core','ajax','translations.php'),{
|
$.ajax(OC.filePath('core','ajax','translations.php'),{
|
||||||
async:false,//todo a proper sollution for this without sync ajax calls
|
async:false,//todo a proper sollution for this without sync ajax calls
|
||||||
|
@ -46,7 +48,8 @@ function t(app,text, vars){
|
||||||
t.cache[app] = [];
|
t.cache[app] = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var _build = function (text, vars) {
|
var _build = function (text, vars, count) {
|
||||||
|
// FIXME: replace %n with content of count
|
||||||
return text.replace(/{([^{}]*)}/g,
|
return text.replace(/{([^{}]*)}/g,
|
||||||
function (a, b) {
|
function (a, b) {
|
||||||
var r = vars[b];
|
var r = vars[b];
|
||||||
|
@ -54,26 +57,40 @@ function t(app,text, vars){
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
var translation = text;
|
||||||
if( typeof( t.cache[app][text] ) !== 'undefined' ){
|
if( typeof( t.cache[app][text] ) !== 'undefined' ){
|
||||||
if(typeof vars === 'object') {
|
translation = t.cache[app][text];
|
||||||
return _build(t.cache[app][text], vars);
|
}
|
||||||
|
|
||||||
|
if(typeof vars === 'object' || typeof count !== 'undefined' ) {
|
||||||
|
return _build(translation, vars, count);
|
||||||
} else {
|
} else {
|
||||||
return t.cache[app][text];
|
return translation;
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(typeof vars === 'object') {
|
|
||||||
return _build(text, vars);
|
|
||||||
} else {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.cache={};
|
t.cache={};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* translate a string
|
||||||
|
* @param app the id of the app for which to translate the string
|
||||||
|
* @param text_singular the string to translate for exactly one object
|
||||||
|
* @param text_plural the string to translate for n objects
|
||||||
|
* @param count number to determine whether to use singular or plural
|
||||||
|
* @param vars (optional) FIXME
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function tp(app, text_singular, text_plural, count, vars){
|
||||||
|
if(count==1){
|
||||||
|
return t(app, text_singular, vars, count);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return t(app, text_plural, vars, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Sanitizes a HTML string
|
* Sanitizes a HTML string
|
||||||
* @param string
|
* @param s string
|
||||||
* @return Sanitized string
|
* @return Sanitized string
|
||||||
*/
|
*/
|
||||||
function escapeHTML(s) {
|
function escapeHTML(s) {
|
||||||
|
|
Loading…
Reference in New Issue