1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
require 'test_helper'
class I18nBackendPluralizationScopeTest < I18n::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
include I18n::Backend::Fallbacks
end
def setup
super
I18n.default_locale = :'en'
I18n.backend = Backend.new
translations = {
i18n: {
plural: {
keys: [:one, :other],
rule: lambda { |n| n == 1 ? :one : :other },
}
},
activerecord: {
models: {
my_model: {
one: 'one model',
other: 'more models',
some_other_key: {
key: 'value'
}
}
}
}
}
store_translations('en', translations)
end
test "pluralization picks :other for 2" do
args = {
scope: [:activerecord, :models],
count: 2,
default: ["My model"]
}
assert_equal 'more models', I18n.translate(:my_model, **args)
end
test "pluralization picks :one for 1" do
args = {
scope: [:activerecord, :models],
count: 1,
default: ["My model"]
}
assert_equal 'one model', I18n.translate(:my_model, **args)
end
end
|