Last active
December 17, 2015 21:29
-
-
Save SamSaffron/5675308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require_dependency 'js_locale_helper' | |
describe JsLocaleHelper do | |
it 'should be able to generate traslations' do | |
JsLocaleHelper.output_locale('en').length.should > 0 | |
end | |
def setup_message_format(format) | |
@ctx = V8::Context.new | |
@ctx.eval('MessageFormat = {locale: {}};') | |
@ctx.load(Rails.root + 'app/assets/javascripts/defer/locale/en.js') | |
compiled = JsLocaleHelper.compile_message_format('en', format) | |
@ctx.eval("var test = #{compiled}") | |
end | |
def localize(opts) | |
@ctx.eval("test(#{opts.to_json})") | |
end | |
it 'handles plurals' do | |
setup_message_format('{NUM_RESULTS, plural, | |
one {1 result} | |
other {# results} | |
}') | |
localize(NUM_RESULTS: 1).should == '1 result' | |
localize(NUM_RESULTS: 2).should == '2 results' | |
end | |
it 'handles double plurals' do | |
setup_message_format('{NUM_RESULTS, plural, | |
one {1 result} | |
other {# results} | |
} and {NUM_APPLES, plural, | |
one {1 apple} | |
other {# apples} | |
}') | |
localize(NUM_RESULTS: 1, NUM_APPLES: 2).should == '1 result and 2 apples' | |
localize(NUM_RESULTS: 2, NUM_APPLES: 1).should == '2 results and 1 apple' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment