mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-26 21:16:23 +02:00
Tests for admin search, simplifications
This commit is contained in:
@@ -339,6 +339,68 @@
|
||||
|
||||
Translator.moduleFactories = {};
|
||||
|
||||
/**
|
||||
* Remove the translator patterns from text
|
||||
* @param {string} text
|
||||
* @returns {string}
|
||||
*/
|
||||
Translator.removePatterns = function removePatterns(text) {
|
||||
var len = text.length;
|
||||
var cursor = 0;
|
||||
var lastBreak = 0;
|
||||
var level = 0;
|
||||
var out = '';
|
||||
var sub;
|
||||
|
||||
while (cursor < len) {
|
||||
sub = text.slice(cursor, cursor + 2);
|
||||
if (sub === '[[') {
|
||||
if (level === 0) {
|
||||
out += text.slice(lastBreak, cursor);
|
||||
}
|
||||
level += 1;
|
||||
cursor += 2;
|
||||
} else if (sub === ']]') {
|
||||
level -= 1;
|
||||
cursor += 2;
|
||||
if (level === 0) {
|
||||
lastBreak = cursor;
|
||||
}
|
||||
} else {
|
||||
cursor += 1;
|
||||
}
|
||||
}
|
||||
out += text.slice(lastBreak, cursor);
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape translator patterns in text
|
||||
* @param {string} text
|
||||
* @returns {string}
|
||||
*/
|
||||
Translator.escape = function escape(text) {
|
||||
return typeof text === 'string' ? text.replace(/\[\[([\S]*?)\]\]/g, '\\[\\[$1\\]\\]') : text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unescape escaped translator patterns in text
|
||||
* @param {string} text
|
||||
* @returns {string}
|
||||
*/
|
||||
Translator.unescape = function unescape(text) {
|
||||
return typeof text === 'string' ? text.replace(/\\\[\\\[([\S]*?)\\\]\\\]/g, '[[$1]]') : text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct a translator pattern
|
||||
*/
|
||||
Translator.compile = function compile() {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
|
||||
return '[[' + args.join(', ') + ']]';
|
||||
};
|
||||
|
||||
return Translator;
|
||||
}());
|
||||
|
||||
@@ -348,12 +410,16 @@
|
||||
*/
|
||||
Translator: Translator,
|
||||
|
||||
compile: Translator.compile,
|
||||
escape: Translator.escape,
|
||||
unescape: Translator.unescape,
|
||||
getLanguage: Translator.getLanguage,
|
||||
|
||||
/**
|
||||
* Legacy translator function for backwards compatibility
|
||||
*/
|
||||
translate: function translate(text, language, callback) {
|
||||
// console.warn('[translator] `translator.translate(text, [lang, ]callback)` is deprecated. ' +
|
||||
// 'Use the `translator.Translator` class instead.');
|
||||
// TODO: deprecate?
|
||||
|
||||
var cb = callback;
|
||||
var lang = language;
|
||||
@@ -373,31 +439,6 @@
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Construct a translator pattern
|
||||
* @param {string} name - Translation name
|
||||
* @param {string[]} args - Optional arguments for the pattern
|
||||
*/
|
||||
compile: function compile() {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
|
||||
return '[[' + args.join(', ') + ']]';
|
||||
},
|
||||
|
||||
/**
|
||||
* Escape translation patterns from text
|
||||
*/
|
||||
escape: function escape(text) {
|
||||
return typeof text === 'string' ? text.replace(/\[\[([\S]*?)\]\]/g, '\\[\\[$1\\]\\]') : text;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unescape translation patterns from text
|
||||
*/
|
||||
unescape: function unescape(text) {
|
||||
return typeof text === 'string' ? text.replace(/\\\[\\\[([\S]*?)\\\]\\\]/g, '[[$1]]') : text;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add translations to the cache
|
||||
*/
|
||||
@@ -422,11 +463,6 @@
|
||||
adaptor.getTranslations(language, namespace, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the language of the current environment, falling back to defaults
|
||||
*/
|
||||
getLanguage: Translator.getLanguage,
|
||||
|
||||
toggleTimeagoShorthand: function toggleTimeagoShorthand() {
|
||||
var tmp = assign({}, jQuery.timeago.settings.strings);
|
||||
jQuery.timeago.settings.strings = assign({}, adaptor.timeagoShort);
|
||||
|
||||
Reference in New Issue
Block a user