From 6fcb3b44156a89feda9293c289175d0dec79cd80 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 13 Aug 2012 04:28:12 -0700 Subject: add jquery.i18n for client side translations --- library/jquery.i18n/jquery.i18n.js | 154 +++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 library/jquery.i18n/jquery.i18n.js (limited to 'library/jquery.i18n/jquery.i18n.js') diff --git a/library/jquery.i18n/jquery.i18n.js b/library/jquery.i18n/jquery.i18n.js new file mode 100644 index 000000000..07ba0ed32 --- /dev/null +++ b/library/jquery.i18n/jquery.i18n.js @@ -0,0 +1,154 @@ +/* + * jQuery i18n plugin + * @requires jQuery v1.1 or later + * + * See http://recursive-design.com/projects/jquery-i18n/ + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + * + * Version: 0.9.2 (201204070102) + */ + (function($) { +/** + * i18n provides a mechanism for translating strings using a jscript dictionary. + * + */ + + +/* + * i18n property list + */ +$.i18n = { + + dict: null, + +/** + * setDictionary() + * Initialise the dictionary and translate nodes + * + * @param property_list i18n_dict : The dictionary to use for translation + */ + setDictionary: function(i18n_dict) { + this.dict = i18n_dict; + }, + +/** + * _() + * The actual translation function. Looks the given string up in the + * dictionary and returns the translation if one exists. If a translation + * is not found, returns the original word + * + * @param string str : The string to translate + * @param property_list params : params for using printf() on the string + * @return string : Translated word + * + */ + _: function (str, params) { + var transl = str; + if (this.dict && this.dict[str]) { + transl = this.dict[str]; + } + return this.printf(transl, params); + }, + +/** + * toEntity() + * Change non-ASCII characters to entity representation + * + * @param string str : The string to transform + * @return string result : Original string with non-ASCII content converted to entities + * + */ + toEntity: function (str) { + var result = ''; + for (var i=0;i 128) + result += "&#"+str.charCodeAt(i)+";"; + else + result += str.charAt(i); + } + return result; + }, + +/** + * stripStr() + * + * @param string str : The string to strip + * @return string result : Stripped string + * + */ + stripStr: function(str) { + return str.replace(/^\s*/, "").replace(/\s*$/, ""); + }, + +/** + * stripStrML() + * + * @param string str : The multi-line string to strip + * @return string result : Stripped string + * + */ + stripStrML: function(str) { + // Split because m flag doesn't exist before JS1.5 and we need to + // strip newlines anyway + var parts = str.split('\n'); + for (var i=0; i 1) { + for(var i=0; i