Ruby On Rails: pluralize for other languages

前端 未结 4 2119
悲&欢浪女
悲&欢浪女 2021-02-14 19:57

I am building apps for a non-english audience. Right now, I use english nouns to name my models, yet I prefer to use native dutch ones. As the convention uses the plural of the

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 20:24

    In addition, as far as views are concerned my preferred way of dealing with pluralizing foreign strings is i18n pluralization. Take a look at a straightforward example below.

    # config/locales/en.yml
    
    en:
      message:
        one: You have 1 message #Your foreign string
        other: You have %{count} messages #Your foreign string
    

    Then in view you can do

    # app/views/messages/index.html.erb
    
    <%= t("message", count: current_user.messages.count) %>
    

    Check official documentation.
    Hope that helps!

提交回复
热议问题