discourse/app/helpers/js_locale_helper.rb

24 lines
781 B
Ruby
Raw Normal View History

module JsLocaleHelper
def self.output_locale(locale)
2013-02-28 14:31:39 -05:00
locale_str = locale.to_s
2013-02-28 14:31:39 -05:00
translations = YAML::load(File.open("#{Rails.root}/config/locales/client.#{locale_str}.yml"))
2013-02-28 14:31:39 -05:00
# We used to split the admin versus the client side, but it's much simpler to just
# include both for now due to the small size of the admin section.
#
# For now, let's leave it split out in the translation file in case we want to split
# it again later, so we'll merge the JSON ourselves.
admin_contents = translations[locale_str].delete('admin_js')
2013-02-28 14:31:39 -05:00
translations[locale_str]['js'].merge!(admin_contents) if admin_contents.present?
2013-02-28 14:31:39 -05:00
result = "I18n.translations = #{translations.to_json};\n"
result << "I18n.locale = '#{locale_str}'\n"
result
end
end