mpartan
mpartan

Reputation: 1316

Ruby on Rails localization resource with translation and nested resources

What I'm trying to achieve has the following idea:

en:
  product:
     category: "Product category"
     category: 
       product: "Product"

So that I would get following results

t("product.category") => "Product category"
t("product.category.product") => "Product"

However the latter category overwrites the first category, so I'm getting like this:

t("product.category") => ":product: Product"
t("product.category.product") => "Product"

Any way to achieve that kind of translation structure that returns the text if asked for the root, or is the Rails translations structured so that it's either a String (translation) or a Hash (nested translations) and there is no way to have "both"?

Upvotes: 1

Views: 589

Answers (1)

torrocus
torrocus

Reputation: 336

Why don't you try it in Rails way?

en:
  activerecord:
    models:
      product: Product
      category: Category
    attributes:
      product:
        category: Product category
      category:
        product: Product

Next you can use methods: Model.model_name.human to show model name or Model.human_attribute_name(attribute) to show attribute name

More information here: http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models

Upvotes: 2

Related Questions