mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 21:53:48 +08:00
a2c04be718
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
38 lines
963 B
Ruby
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
|