Merge pull request #4778 from techAPJ/admin-message-format
FIX: admin locales were not getting converted to message format
This commit is contained in:
commit
dfe1d3adfd
|
@ -100,15 +100,16 @@ module JsLocaleHelper
|
||||||
locale_str = locale.to_s
|
locale_str = locale.to_s
|
||||||
translations = Marshal.load(Marshal.dump(translations_for(locale_str)))
|
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.keys.each do |locale|
|
||||||
translations[locale].keys.each do |k|
|
translations[locale].keys.each do |k|
|
||||||
translations[locale].delete(k) unless k == "js"
|
translations[locale].delete(k) unless k == "js"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
message_formats = strip_out_message_formats!(translations[locale_str]['js'])
|
|
||||||
result = generate_message_format(message_formats, locale_str)
|
|
||||||
|
|
||||||
# I18n
|
# I18n
|
||||||
result << "I18n.translations = #{translations.to_json};\n"
|
result << "I18n.translations = #{translations.to_json};\n"
|
||||||
result << "I18n.locale = '#{locale_str}';\n"
|
result << "I18n.locale = '#{locale_str}';\n"
|
||||||
|
|
|
@ -90,6 +90,9 @@ describe JsLocaleHelper do
|
||||||
"test_MF" => "{HELLO} {COUNT, plural, one {1 duck} other {# ducks}}",
|
"test_MF" => "{HELLO} {COUNT, plural, one {1 duck} other {# ducks}}",
|
||||||
"error_MF" => "{{BLA}",
|
"error_MF" => "{{BLA}",
|
||||||
"simple_MF" => "{COUNT, plural, one {1} other {#}}"
|
"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("error_MF", { HELLO: "hi", COUNT: 3 })')).to match(/Invalid Format/)
|
||||||
expect(ctx.eval('I18n.messageFormat("missing", {})')).to match(/missing/)
|
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("simple_MF", {})')).to match(/COUNT/) # error
|
||||||
|
expect(ctx.eval('I18n.messageFormat("foo_MF", { HELLO: "hi", COUNT: 4 })')).to eq("hi 4 ducks")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'load pluralizations rules before precompile' do
|
it 'load pluralizations rules before precompile' do
|
||||||
|
|
Loading…
Reference in New Issue