mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #3609 from riking/patch-7
FEATURE: Localization fallbacks
This commit is contained in:
@@ -52,6 +52,8 @@ I18n.PLACEHOLDER = /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm;
|
||||
|
||||
I18n.fallbackRules = {};
|
||||
|
||||
I18n.noFallbacks = false;
|
||||
|
||||
I18n.pluralizationRules = {
|
||||
en: function(n) {
|
||||
return n === 0 ? ["zero", "none", "other"] : n === 1 ? "one" : "other";
|
||||
@@ -192,6 +194,15 @@ 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) {
|
||||
options.locale = this.defaultLocale;
|
||||
translation = this.lookup(scope, options);
|
||||
}
|
||||
if (!translation && this.currentLocale() !== 'en' && !this.noFallbacks) {
|
||||
options.locale = 'en';
|
||||
translation = this.lookup(scope, options);
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof translation === "object") {
|
||||
@@ -513,6 +524,7 @@ I18n.enable_verbose_localization = function(){
|
||||
var keys = {};
|
||||
var t = I18n.t;
|
||||
|
||||
I18n.noFallbacks = true;
|
||||
|
||||
I18n.t = I18n.translate = function(scope, value){
|
||||
var current = keys[scope];
|
||||
|
||||
@@ -155,6 +155,8 @@ class ApplicationController < ActionController::Base
|
||||
else
|
||||
SiteSetting.default_locale
|
||||
end
|
||||
|
||||
I18n.fallbacks.ensure_loaded!
|
||||
end
|
||||
|
||||
def store_preloaded(key, json)
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
Discourse.Environment = '<%= Rails.env %>';
|
||||
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
||||
Discourse.LetterAvatarVersion = '<%= LetterAvatar.version %>';
|
||||
I18n.defaultLocale = '<%= SiteSetting.default_locale %>';
|
||||
PreloadStore.get("customEmoji").forEach(function(emoji) {
|
||||
Discourse.Dialect.registerEmoji(emoji.name, emoji.url);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user