FIX: admin locales were not getting converted to message format

This commit is contained in:
Arpit Jalan 2017-03-25 01:12:23 +05:30
parent 6875007366
commit 3449339fea
2 changed files with 8 additions and 3 deletions

View File

@ -100,15 +100,16 @@ module JsLocaleHelper
locale_str = locale.to_s
translations = Marshal.load(Marshal.dump(translations_for(locale_str)))
message_formats = strip_out_message_formats!(translations[locale_str]['js'])
message_formats.merge!(strip_out_message_formats!(translations[locale_str]['admin_js']))
result = generate_message_format(message_formats, locale_str)
translations.keys.each do |locale|
translations[locale].keys.each do |k|
translations[locale].delete(k) unless k == "js"
end
end
message_formats = strip_out_message_formats!(translations[locale_str]['js'])
result = generate_message_format(message_formats, locale_str)
# I18n
result << "I18n.translations = #{translations.to_json};\n"
result << "I18n.locale = '#{locale_str}';\n"

View File

@ -90,6 +90,9 @@ describe JsLocaleHelper do
"test_MF" => "{HELLO} {COUNT, plural, one {1 duck} other {# ducks}}",
"error_MF" => "{{BLA}",
"simple_MF" => "{COUNT, plural, one {1} other {#}}"
},
"admin_js" => {
"foo_MF" => "{HELLO} {COUNT, plural, one {1 duck} other {# ducks}}"
}
}
})
@ -105,6 +108,7 @@ describe JsLocaleHelper do
expect(ctx.eval('I18n.messageFormat("error_MF", { HELLO: "hi", COUNT: 3 })')).to match(/Invalid Format/)
expect(ctx.eval('I18n.messageFormat("missing", {})')).to match(/missing/)
expect(ctx.eval('I18n.messageFormat("simple_MF", {})')).to match(/COUNT/) # error
expect(ctx.eval('I18n.messageFormat("foo_MF", { HELLO: "hi", COUNT: 4 })')).to eq("hi 4 ducks")
end
it 'load pluralizations rules before precompile' do