discourse/app/controllers/extra_locales_controller.rb

38 lines
964 B
Ruby
Raw Normal View History

2016-08-26 04:33:29 +08:00
class ExtraLocalesController < ApplicationController
layout :false
skip_before_action :check_xhr, :preload_json
2016-08-26 04:33:29 +08:00
def show
bundle = params[:bundle]
raise Discourse::InvalidAccess.new unless bundle =~ /^(admin|wizard)$/
2016-08-26 04:33:29 +08:00
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 = ""
2016-08-26 04:33:29 +08:00
if for_key.present?
if plugin_for_key = JsLocaleHelper.plugin_translations(locale_str)[bundle_str]
for_key.deep_merge!(plugin_for_key)
end
2016-08-26 04:33:29 +08:00
js = <<~JS.squish
(function() {
if (window.I18n) {
window.I18n.extras = window.I18n.extras || [];
window.I18n.extras.push(#{for_key.to_json});
}
})();
JS
end
render plain: js, content_type: "application/javascript"
2016-08-26 04:33:29 +08:00
end
end