summaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
authorJakob Sack <mail@jakobsack.de>2013-07-07 20:26:09 +0200
committerJakob Sack <mail@jakobsack.de>2013-07-07 20:26:09 +0200
commit4e214883d64acf4dc9cc3191780086d0a9dac60f (patch)
treebfaa1087361106522722f553ff99d40be5a344c5 /core/js/js.js
parent560839195e97abdaca4f8c144a6a760a0ab90c19 (diff)
downloadnextcloud-server-4e214883d64acf4dc9cc3191780086d0a9dac60f.tar.gz
nextcloud-server-4e214883d64acf4dc9cc3191780086d0a9dac60f.zip
Partly integrate plural translations into js
Diffstat (limited to 'core/js/js.js')
-rw-r--r--core/js/js.js55
1 files changed, 36 insertions, 19 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 3904787c4e5..15cf1d286fa 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -1,6 +1,6 @@
/**
* Disable console output unless DEBUG mode is enabled.
- * Add
+ * Add
* define('DEBUG', true);
* To the end of config/config.php to enable debug mode.
* The undefined checks fix the broken ie8 console
@@ -28,9 +28,11 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log ==
* translate a string
* @param app the id of the app for which to translate the string
* @param text the string to translate
+ * @param vars (optional) FIXME
+ * @param count (optional) number to replace %n with
* @return string
*/
-function t(app,text, vars){
+function t(app, text, vars, count){
if( !( t.cache[app] )){
$.ajax(OC.filePath('core','ajax','translations.php'),{
async:false,//todo a proper sollution for this without sync ajax calls
@@ -46,7 +48,8 @@ function t(app,text, vars){
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,
function (a, b) {
var r = vars[b];
@@ -54,30 +57,44 @@ function t(app,text, vars){
}
);
};
+ var translation = text;
if( typeof( t.cache[app][text] ) !== 'undefined' ){
- if(typeof vars === 'object') {
- return _build(t.cache[app][text], vars);
- } else {
- return t.cache[app][text];
- }
+ translation = t.cache[app][text];
}
- else{
- if(typeof vars === 'object') {
- return _build(text, vars);
- } else {
- return text;
- }
+
+ if(typeof vars === 'object' || typeof count !== 'undefined' ) {
+ return _build(translation, vars, count);
+ } else {
+ return translation;
}
}
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
-* @param string
+* @param s string
* @return Sanitized string
*/
function escapeHTML(s) {
- return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('"').join('&quot;');
+ return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('"').join('&quot;');
}
/**
@@ -741,7 +758,7 @@ OC.get=function(name) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
-
+
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
if(!context){
@@ -760,7 +777,7 @@ OC.set=function(name, value) {
var namespaces = name.split(".");
var tail = namespaces.pop();
var context=window;
-
+
for(var i = 0; i < namespaces.length; i++) {
if(!context[namespaces[i]]){
context[namespaces[i]]={};