discourse/app/controllers/extra_locales_controller.rb
Régis Hanol a2c04be718 FIX: eradicate I18n fallback issues 💣
FIX: client's translation overrides were not working when the current locale was missing a key
FIX: ExtraLocalesController.show was not properly handling multiple translations
FIX: JsLocaleHelper#output_locale was not properly handling multiple translations

FIX: ExtraLocalesController.show's spec which was randomly failing
FIX: JsLocaleHelper#output_locale was muting cached translations hashes

REFACTOR: move 'enableVerboseLocalization' to the 'localization' initializer
REFACTOR: remove unused I18n.js methods (getFallbacks, localize, parseDate, toTime, strftime, toCurrency, toPercentage)
REFACTOR: remove all I18n.pluralizationRules and instead use MessageFormat's pluralization rules

TEST: add tests for localization initializer
TEST: add tests for I18n.js
2017-02-24 11:31:21 +01:00

38 lines
963 B
Ruby

class ExtraLocalesController < ApplicationController
layout :false
skip_before_filter :check_xhr, :preload_json
def show
bundle = params[:bundle]
raise Discourse::InvalidAccess.new unless bundle =~ /^(admin|wizard)$/
locale_str = I18n.locale.to_s
bundle_str = "#{bundle}_js"
translations = JsLocaleHelper.translations_for(locale_str)
for_key = {}
translations.values.each { |v| for_key.deep_merge!(v[bundle_str]) if v.has_key?(bundle_str) }
js = ""
if for_key.present?
if plugin_for_key = JsLocaleHelper.plugin_translations(locale_str)[bundle_str]
for_key.deep_merge!(plugin_for_key)
end
js = <<~JS.squish
(function() {
if (window.I18n) {
window.I18n.extras = window.I18n.extras || [];
window.I18n.extras.push(#{for_key.to_json});
}
})();
JS
end
render text: js, content_type: "application/javascript"
end
end