2016-08-25 16:33:29 -04:00
|
|
|
class ExtraLocalesController < ApplicationController
|
|
|
|
|
|
|
|
layout :false
|
|
|
|
skip_before_filter :check_xhr, :preload_json
|
|
|
|
|
|
|
|
def show
|
|
|
|
bundle = params[:bundle]
|
2017-02-24 05:31:21 -05:00
|
|
|
raise Discourse::InvalidAccess.new unless bundle =~ /^(admin|wizard)$/
|
2016-08-25 16:33:29 -04:00
|
|
|
|
2016-09-28 16:26:36 -04:00
|
|
|
locale_str = I18n.locale.to_s
|
2017-02-24 05:31:21 -05:00
|
|
|
bundle_str = "#{bundle}_js"
|
|
|
|
|
2016-09-28 16:26:36 -04:00
|
|
|
translations = JsLocaleHelper.translations_for(locale_str)
|
2017-02-24 05:31:21 -05:00
|
|
|
|
|
|
|
for_key = {}
|
|
|
|
translations.values.each { |v| for_key.deep_merge!(v[bundle_str]) if v.has_key?(bundle_str) }
|
|
|
|
|
2016-09-30 02:29:30 -04:00
|
|
|
js = ""
|
2016-08-25 16:33:29 -04:00
|
|
|
|
2016-09-30 02:29:30 -04:00
|
|
|
if for_key.present?
|
2017-02-24 05:31:21 -05:00
|
|
|
if plugin_for_key = JsLocaleHelper.plugin_translations(locale_str)[bundle_str]
|
2016-09-30 02:29:30 -04:00
|
|
|
for_key.deep_merge!(plugin_for_key)
|
2016-09-28 16:26:36 -04:00
|
|
|
end
|
2016-08-25 16:33:29 -04:00
|
|
|
|
2017-02-24 05:31:21 -05:00
|
|
|
js = <<~JS.squish
|
|
|
|
(function() {
|
|
|
|
if (window.I18n) {
|
|
|
|
window.I18n.extras = window.I18n.extras || [];
|
|
|
|
window.I18n.extras.push(#{for_key.to_json});
|
|
|
|
}
|
|
|
|
})();
|
2016-09-30 02:29:30 -04:00
|
|
|
JS
|
|
|
|
end
|
|
|
|
|
2016-08-25 16:33:29 -04:00
|
|
|
render text: js, content_type: "application/javascript"
|
|
|
|
end
|
|
|
|
end
|