From 3449339fea86b0755408bbac7494fb1c73eb1fef Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sat, 25 Mar 2017 01:12:23 +0530 Subject: [PATCH] FIX: admin locales were not getting converted to message format --- lib/js_locale_helper.rb | 7 ++++--- spec/components/js_locale_helper_spec.rb | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 137dc2d4683..44a2fe537ea 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -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" diff --git a/spec/components/js_locale_helper_spec.rb b/spec/components/js_locale_helper_spec.rb index 17f0fcecdd6..b5a658f52b2 100644 --- a/spec/components/js_locale_helper_spec.rb +++ b/spec/components/js_locale_helper_spec.rb @@ -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