문제

I have a model with a translation that can be pluralized:

en:
  activerecord:
    models:
      user:
        one: User
        other: Users

If I call this translation directly, I get these results:

t("activerecord.models.user", count: 1)
=> User

t("activerecord.models.user", count: 2)
=> Users

t("activerecord.models.user")
=> {:one=>"User", :other=>"Users"}

Is there a way to get this last translation to default to "User"?

도움이 되었습니까?

해결책

If you are going to sometimes pass a count and other times not, you should set up separate keys for them:

counted_user:
  one: User
  other: Users
user: User

t("activerecord.models.counted_user", count: 1)
t("activerecord.models.counted_user", count: 2)
t("activerecord.models.user")

If the default is only used in minimal circumstances that don't warrant a separate key, just call it directly:

t("activerecord.models.user.one")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top