From ae81523aa52412da79e874bc7006c26b550ef5ab Mon Sep 17 00:00:00 2001 From: Aleksandr Kruglov Date: Sat, 15 Jun 2013 02:31:36 +0400 Subject: [PATCH 1/3] It maybe worth load pluralizations rules before compile? --- lib/js_locale_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 61847405cf1..3db929bfa77 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -73,6 +73,7 @@ module JsLocaleHelper def self.compile_message_format(locale, format) ctx = V8::Context.new ctx.load(Rails.root + 'lib/javascripts/messageformat.js') + ctx.load(Rails.root + "lib/javascripts/locale/#{locale}.js") ctx.eval("mf = new MessageFormat('#{locale}');") ctx.eval("mf.precompile(mf.parse(#{format.inspect}))") From c964c5c0d5eac17fd15108271d461741f7f3685c Mon Sep 17 00:00:00 2001 From: Krugloff Date: Sun, 16 Jun 2013 00:50:59 +0400 Subject: [PATCH 2/3] Add test for load plurals before precompile --- spec/components/js_locale_helper_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/components/js_locale_helper_spec.rb b/spec/components/js_locale_helper_spec.rb index ceab7ff6e21..c3a8060ab55 100644 --- a/spec/components/js_locale_helper_spec.rb +++ b/spec/components/js_locale_helper_spec.rb @@ -79,4 +79,9 @@ describe JsLocaleHelper do ctx.eval('I18n.messageFormat("simple_MF", {})').should =~ /COUNT/ # error end + it 'load pluralizations rules before precompile' do + message = JsLocaleHelper.compile_message_format('ru', 'format') + message.should_not match 'Plural Function not found' + end + end From d0901289e71d87502dd870dad169446aad2b2f0e Mon Sep 17 00:00:00 2001 From: Krugloff Date: Sun, 16 Jun 2013 02:46:56 +0400 Subject: [PATCH 3/3] File exists check --- lib/js_locale_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 3db929bfa77..d8d9bb83188 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -73,7 +73,8 @@ module JsLocaleHelper def self.compile_message_format(locale, format) ctx = V8::Context.new ctx.load(Rails.root + 'lib/javascripts/messageformat.js') - ctx.load(Rails.root + "lib/javascripts/locale/#{locale}.js") + path = Rails.root + "lib/javascripts/locale/#{locale}.js" + ctx.load(path) if File.exists?(path) ctx.eval("mf = new MessageFormat('#{locale}');") ctx.eval("mf.precompile(mf.parse(#{format.inspect}))")