mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 12:08:12 -05:00
Support for other i18n bundles
This commit is contained in:
@@ -92,6 +92,24 @@ I18n.isValidNode = function(obj, node, undefined) {
|
||||
return obj[node] !== null && obj[node] !== undefined;
|
||||
};
|
||||
|
||||
function checkExtras(origScope, sep, extras) {
|
||||
if (!extras || extras.length === 0) { return; }
|
||||
|
||||
for (var i=0; i<extras.length; i++) {
|
||||
var messages = extras[i];
|
||||
scope = origScope.split(sep);
|
||||
scope.shift();
|
||||
|
||||
while (messages && scope.length > 0) {
|
||||
currentScope = scope.shift();
|
||||
messages = messages[currentScope];
|
||||
}
|
||||
if (messages) {
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
I18n.lookup = function(scope, options) {
|
||||
options = options || {};
|
||||
var lookupInitialScope = scope,
|
||||
@@ -110,13 +128,20 @@ I18n.lookup = function(scope, options) {
|
||||
scope = options.scope.toString() + this.defaultSeparator + scope;
|
||||
}
|
||||
|
||||
scope = scope.split(this.defaultSeparator);
|
||||
var origScope = "" + scope;
|
||||
|
||||
scope = origScope.split(this.defaultSeparator);
|
||||
|
||||
while (messages && scope.length > 0) {
|
||||
currentScope = scope.shift();
|
||||
messages = messages[currentScope];
|
||||
}
|
||||
|
||||
if (!messages) {
|
||||
messages = checkExtras(origScope, this.defaultSeparator, this.extras);
|
||||
}
|
||||
|
||||
|
||||
if (!messages) {
|
||||
if (I18n.fallbacks) {
|
||||
var fallbacks = this.getFallbacks(locale);
|
||||
@@ -192,7 +217,9 @@ I18n.interpolate = function(message, options) {
|
||||
};
|
||||
|
||||
I18n.translate = function(scope, options) {
|
||||
|
||||
options = this.prepareOptions(options);
|
||||
|
||||
var translation = this.lookup(scope, options);
|
||||
// Fallback to the default locale
|
||||
if (!translation && this.currentLocale() !== this.defaultLocale && !this.noFallbacks) {
|
||||
|
||||
Reference in New Issue
Block a user