OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
api
/
util
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 06:12:10 AM
rwxr-xr-x
📄
Class.ts
4.15 KB
02/20/2020 06:12:13 AM
rw-r--r--
📄
Color.ts
5.3 KB
02/20/2020 06:12:14 AM
rw-r--r--
📄
Delay.ts
6.14 KB
02/20/2020 06:12:14 AM
rw-r--r--
📄
EventDispatcher.ts
10.97 KB
02/20/2020 06:12:15 AM
rw-r--r--
📄
FakeStorage.ts
986 bytes
02/20/2020 06:12:15 AM
rw-r--r--
📄
I18n.ts
4.92 KB
02/20/2020 06:12:16 AM
rw-r--r--
📄
JSON.ts
1.63 KB
02/20/2020 06:12:16 AM
rw-r--r--
📄
JSONP.ts
1 KB
02/20/2020 06:12:17 AM
rw-r--r--
📄
JSONRequest.ts
3.36 KB
02/20/2020 06:12:17 AM
rw-r--r--
📄
LocalStorage.ts
866 bytes
02/20/2020 06:12:18 AM
rw-r--r--
📄
Observable.ts
4.92 KB
02/20/2020 06:12:18 AM
rw-r--r--
📄
Promise.ts
5.46 KB
02/20/2020 06:12:19 AM
rw-r--r--
📄
Tools.ts
12.15 KB
02/20/2020 06:12:19 AM
rw-r--r--
📄
URI.ts
12.03 KB
02/20/2020 06:12:20 AM
rw-r--r--
📄
VK.ts
1.22 KB
02/20/2020 06:12:20 AM
rw-r--r--
📄
XHR.ts
3.78 KB
02/20/2020 06:12:21 AM
rw-r--r--
Editing: I18n.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import { Type, Obj, Cell } from '@ephox/katamari'; /** * I18n class that handles translation of TinyMCE UI. * Uses po style with csharp style parameters. * * @class tinymce.util.I18n */ export interface RawString { raw: string; } export type TokenisedString = string[]; export type Untranslated = any; export type TranslatedString = string; export type TranslateIfNeeded = Untranslated | TranslatedString; const isRaw = (str: any): str is RawString => Type.isObject(str) && Obj.has(str, 'raw'); const isTokenised = (str: any): str is TokenisedString => Type.isArray(str) && str.length > 1; const data: Record<string, Record<string, string>> = {}; const currentCode = Cell('en'); const getData = (): Record<string, Record<string, string>> => { return Obj.map(data, (value) => ({ ...value })); }; /** * Sets the current language code. * * @method setCode * @param {String} newCode Current language code. */ const setCode = (newCode: string) => { if (newCode) { currentCode.set(newCode); } }; /** * Returns the current language code. * * @method getCode * @return {String} Current language code. */ const getCode = (): string => currentCode.get(); /** * Adds translations for a specific language code. * Translation keys are set to be case insensitive. * * @method add * @param {String} code Language code like sv_SE. * @param {Object} items Name/value object where key is english and value is the translation. */ const add = (code: string, items: Record<string, string>) => { let langData = data[code]; if (!langData) { data[code] = langData = {}; } for (const name in items) { langData[name.toLowerCase()] = items[name]; } }; /** * Translates the specified text. * * It has a few formats: * I18n.translate("Text"); * I18n.translate(["Text {0}/{1}", 0, 1]); * I18n.translate({raw: "Raw string"}); * * @method translate * @param {String/Object/Array} text Text to translate. * @return {String} String that got translated. */ const translate = (text: Untranslated): TranslatedString => { const langData = data[currentCode.get()] || {}; /** * number - string * null, undefined and empty string - empty string * array - comma-delimited string * object - in [object Object] * function - in [object Function] * * @param obj * @returns {string} */ const toString = function (obj) { if (Type.isFunction(obj)) { return Object.prototype.toString.call(obj); } return !isEmpty(obj) ? '' + obj : ''; }; const isEmpty = function (text) { return text === '' || text === null || text === undefined; }; const getLangData = function (text) { // make sure we work on a string and return a string const textstr = toString(text); const lowercaseTextstr = textstr.toLowerCase(); return Obj.has(langData, lowercaseTextstr) ? toString(langData[lowercaseTextstr]) : textstr; }; const removeContext = function (str: string) { return str.replace(/{context:\w+}$/, ''); }; const translated = (text): TranslatedString => { // TODO: When we figure out how to return a type Translated that fails if you give a String, we implement here return text; }; // empty strings if (isEmpty(text)) { return translated(''); } // Raw, already translated if (isRaw(text)) { return translated(toString(text.raw)); } // Tokenised {translations} if (isTokenised(text)) { const values = text.slice(1); const substitued = getLangData(text[0]).replace(/\{([0-9]+)\}/g, function ($1, $2) { return Obj.has(values, $2) ? toString(values[$2]) : $1; }); return translated(removeContext(substitued)); } // straight forward translation mapping return translated(removeContext(getLangData(text))); }; /** * Returns true/false if the currently active language pack is rtl or not. * * @method isRtl * @return {Boolean} True if the current language pack is rtl. */ const isRtl = () => { return Obj.get(data, currentCode.get()) .bind((items) => Obj.get(items, '_dir')) .exists((dir) => dir === 'rtl'); }; /** * Returns true/false if specified language pack exists. * * @method hasCode * @param {String} code Code to check for. * @return {Boolean} True if the current language pack for the specified code exists. */ const hasCode = (code: string) => Obj.has(data, code); interface I18n { getData (): Record<string, Record<string, string>>; setCode (newCode: string): void; getCode (): string; add (code: string, items: Record<string, string>): void; translate (text: Untranslated): TranslatedString; isRtl (): boolean; hasCode (code: string): boolean; } const I18n: I18n = { getData, setCode, getCode, add, translate, isRtl, hasCode }; export default I18n;