【发布时间】:2017-07-26 16:41:28
【问题描述】:
我为韩语语言环境添加了自定义复数规则,想知道是否可以使用 Rspec 进行测试。要添加自定义规则,我在 /config/initializers/pluralization.rb 中添加了以下代码:
require "i18n/backend/pluralization"
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
并在 config/locales/plurals.rb 中添加了自定义规则,目前为
{
:ko => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }
}
当我尝试使用 rails 控制台对其进行测试时,我看到自定义规则已生效,但是当我在运行 Rspec 测试时在我的 spec 文件夹中尝试相同的翻译时,我收到以下错误:
I18n::InvalidPluralizationData: translation data {:other=>"%{count} xxxxxxxx"} can not be used with :count => 1
我的规范文件如下所示: 路径:/spec/locales/default_pluralization_key_ko_spec.rb
Rspec.describe "Korean Locale Pluralization Test" do
describe "checking korean" do
it "korean pluralization with keys only :other" do
I18n.locale = :ko
I18n.t('views.project.drawing_log.upload_sub_text', count:1)
end
end
end
【问题讨论】:
-
你的规范文件是什么样子的?
-
@spickermann 更新了问题以添加规范文件。
标签: ruby-on-rails ruby rspec internationalization