Stan Blog

一些筆記的記錄

[Rails] Pluralize i18n

rails i18n 如遇到單複數的情況可以這樣寫

en:
  notification:
    one: You have 1 notification
    other: You have %{count} notifications

在指定的 key 下增加 oneother 兩個 key,並將數量帶入 other

<%= t("notification", count: current_user.notifications.count) %>

i18n 就會自動判斷單複數做對應的顯示

Ref:

Comments

comments powered by Disqus