4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
12 * I18n class that handles translation of TinyMCE UI.
13 * Uses po style with csharp style parameters.
15 * @class tinymce.util.I18n
17 define("tinymce/util/I18n", [], function() {
24 * Adds translations for a specific language code.
27 * @param {String} code Language code like sv_SE.
28 * @param {Array} items Name/value array with English en_US to sv_SE.
30 add: function(code, items) {
31 for (var name in items) {
32 data[name] = items[name];
37 * Translates the specified text.
39 * It has a few formats:
40 * I18n.translate("Text");
41 * I18n.translate(["Text {0}/{1}", 0, 1]);
42 * I18n.translate({raw: "Raw string"});
45 * @param {String/Object/Array} text Text to translate.
46 * @return {String} String that got translated.
48 translate: function(text) {
49 if (typeof(text) == "undefined") {
53 if (typeof(text) != "string" && text.raw) {
58 var values = text.slice(1);
60 text = (data[text[0]] || text[0]).replace(/\{([^\}]+)\}/g, function(match1, match2) {
61 return values[match2];
65 return data[text] || text;