2016-08-25 15:33:29 -05:00
|
|
|
class ExtraLocalesController < ApplicationController
|
|
|
|
|
|
|
|
layout :false
|
|
|
|
skip_before_filter :check_xhr, :preload_json
|
|
|
|
|
|
|
|
def show
|
|
|
|
bundle = params[:bundle]
|
|
|
|
raise Discourse::InvalidAccess.new unless bundle =~ /^[a-z]+$/
|
|
|
|
|
2016-09-28 15:26:36 -05:00
|
|
|
locale_str = I18n.locale.to_s
|
|
|
|
translations = JsLocaleHelper.translations_for(locale_str)
|
|
|
|
for_key = translations[locale_str]["#{bundle}_js"]
|
2016-09-30 01:29:30 -05:00
|
|
|
js = ""
|
2016-08-25 15:33:29 -05:00
|
|
|
|
2016-09-30 01:29:30 -05:00
|
|
|
if for_key.present?
|
|
|
|
if plugin_for_key = JsLocaleHelper.plugin_translations(locale_str)["#{bundle}_js"]
|
|
|
|
for_key.deep_merge!(plugin_for_key)
|
2016-09-28 15:26:36 -05:00
|
|
|
end
|
2016-08-25 15:33:29 -05:00
|
|
|
|
2016-09-30 01:29:30 -05:00
|
|
|
js = <<~JS
|
|
|
|
(function() {
|
|
|
|
if (window.I18n) {
|
|
|
|
window.I18n.extras = window.I18n.extras || [];
|
|
|
|
window.I18n.extras.push(#{for_key.to_json});
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
JS
|
|
|
|
end
|
|
|
|
|
2016-08-25 15:33:29 -05:00
|
|
|
render text: js, content_type: "application/javascript"
|
|
|
|
end
|
|
|
|
end
|