2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

Add JsLocaleHelper tests for i18n fallback

This commit is contained in:
Kane York 2015-07-15 14:23:41 -07:00
parent ff219bc65c
commit cb395662d0
2 changed files with 104 additions and 25 deletions

View file

@ -1,7 +1,7 @@
module JsLocaleHelper
def self.load_translations(locale)
@loaded_translations ||= {}
@loaded_translations ||= HashWithIndifferentAccess.new
@loaded_translations[locale] ||= begin
locale_str = locale.to_s
@ -69,19 +69,21 @@ module JsLocaleHelper
end
end
def self.output_locale(locale, request=nil)
current_locale = I18n.locale
I18n.locale = locale.to_sym
def self.output_locale(locale)
locale_sym = locale.to_sym
locale_str = locale.to_s
current_locale = I18n.locale
I18n.locale = locale_sym
site_locale = SiteSetting.default_locale.to_sym
if locale == :en
translations = load_translations(locale)
elsif locale == site_locale || site_locale == :en
translations = load_translations_merged(locale, :en)
if locale_sym == :en
translations = load_translations(locale_sym)
elsif locale_sym == site_locale || site_locale == :en
translations = load_translations_merged(locale_sym, :en)
else
translations = load_translations_merged(locale, site_locale, :en)
translations = load_translations_merged(locale_sym, site_locale, :en)
end
message_formats = strip_out_message_formats!(translations[locale_str]['js'])