在 Ruby on Rails 中,ordinalize 方法在 :de 语言环境中不起作用。给出的错误是:
> 1.ordinalize
=> "translation missing: de.number.nth.ordinalized"
重现这个很容易:
rails new test1
rails-i18n
gem 添加到 Gemfile 并运行 bundle
==> config/locales/de.yml <==
de:
hello: "Hallo Welt"
==> config/locales/en.yml <==
en:
hello: "Hello world"
==> config/locales/fr.yml <==
fr:
hello: "Bonjour le monde"
然后尝试在 Rails 控制台中使用 ordinalize:
test1 git:(main) ✗ rails console
Loading development environment (Rails 7.0.4.3)
3.1.2 :001 > I18n.locale
=> :en
3.1.2 :002 > 1.ordinalize
=> "1st"
3.1.2 :003 > I18n.locale = :fr
=> :fr
3.1.2 :004 > 1.ordinalize
=> "1er"
3.1.2 :005 > I18n.locale = :de
=> :de
3.1.2 :006 > 1.ordinalize
=> "translation missing: de.number.nth.ordinalized"
查看 rails-i18n 源代码,那里似乎有代码可以处理
number.nth.ordinalized
German 和 French 中的翻译键
如果我在我的 de.yml 文件中手动添加一个
number.nth.ordinalized
键,那么就会找到该翻译。
有人能帮我理解为什么这不起作用,最好解释一下需要改变什么才能让它起作用。
非常感谢。