src/pyams_skin/resources/js/ext/tinymce/dev/classes/util/I18n.js
changeset 69 a361355b55c7
equal deleted inserted replaced
68:fd8fb93e1b6a 69:a361355b55c7
       
     1 /**
       
     2  * I18n.js
       
     3  *
       
     4  * Copyright, Moxiecode Systems AB
       
     5  * Released under LGPL License.
       
     6  *
       
     7  * License: http://www.tinymce.com/license
       
     8  * Contributing: http://www.tinymce.com/contributing
       
     9  */
       
    10 
       
    11 /**
       
    12  * I18n class that handles translation of TinyMCE UI.
       
    13  * Uses po style with csharp style parameters.
       
    14  *
       
    15  * @class tinymce.util.I18n
       
    16  */
       
    17 define("tinymce/util/I18n", [], function() {
       
    18 	"use strict";
       
    19 
       
    20 	var data = {}, code = "en";
       
    21 
       
    22 	return {
       
    23 		/**
       
    24 		 * Sets the current language code.
       
    25 		 *
       
    26 		 * @method setCode
       
    27 		 * @param {String} newCode Current language code.
       
    28 		 */
       
    29 		setCode: function(newCode) {
       
    30 			if (newCode) {
       
    31 				code = newCode;
       
    32 				this.rtl = this.data[newCode] ? this.data[newCode]._dir === 'rtl' : false;
       
    33 			}
       
    34 		},
       
    35 
       
    36 		/**
       
    37 		 * Returns the current language code.
       
    38 		 *
       
    39 		 * @return {String} Current language code.
       
    40 		 */
       
    41 		getCode: function() {
       
    42 			return code;
       
    43 		},
       
    44 
       
    45 		/**
       
    46 		 * Property gets set to true if a RTL language pack was loaded.
       
    47 		 *
       
    48 		 * @property rtl
       
    49 		 * @type Boolean
       
    50 		 */
       
    51 		rtl: false,
       
    52 
       
    53 		/**
       
    54 		 * Adds translations for a specific language code.
       
    55 		 *
       
    56 		 * @method add
       
    57 		 * @param {String} code Language code like sv_SE.
       
    58 		 * @param {Array} items Name/value array with English en_US to sv_SE.
       
    59 		 */
       
    60 		add: function(code, items) {
       
    61 			var langData = data[code];
       
    62 
       
    63 			if (!langData) {
       
    64 				data[code] = langData = {};
       
    65 			}
       
    66 
       
    67 			for (var name in items) {
       
    68 				langData[name] = items[name];
       
    69 			}
       
    70 
       
    71 			this.setCode(code);
       
    72 		},
       
    73 
       
    74 		/**
       
    75 		 * Translates the specified text.
       
    76 		 *
       
    77 		 * It has a few formats:
       
    78 		 * I18n.translate("Text");
       
    79 		 * I18n.translate(["Text {0}/{1}", 0, 1]);
       
    80 		 * I18n.translate({raw: "Raw string"});
       
    81 		 *
       
    82 		 * @method translate
       
    83 		 * @param {String/Object/Array} text Text to translate.
       
    84 		 * @return {String} String that got translated.
       
    85 		 */
       
    86 		translate: function(text) {
       
    87 			var langData;
       
    88 
       
    89 			langData = data[code];
       
    90 			if (!langData) {
       
    91 				langData = {};
       
    92 			}
       
    93 
       
    94 			if (typeof text == "undefined") {
       
    95 				return text;
       
    96 			}
       
    97 
       
    98 			if (typeof text != "string" && text.raw) {
       
    99 				return text.raw;
       
   100 			}
       
   101 
       
   102 			if (text.push) {
       
   103 				var values = text.slice(1);
       
   104 
       
   105 				text = (langData[text[0]] || text[0]).replace(/\{([0-9]+)\}/g, function(match1, match2) {
       
   106 					return values[match2];
       
   107 				});
       
   108 			}
       
   109 
       
   110 			return (langData[text] || text).replace(/{context:\w+}$/, '');
       
   111 		},
       
   112 
       
   113 		data: data
       
   114 	};
       
   115 });