knh170
knh170

Reputation: 2990

Rails - I18n: How do I find out translation path?

I have a form with "resources" which I want to translate. I defined the translation in xx.yml:

xx:
  activerecord:
    models: 
      user:
        email: "xx"

And also tried "one" and "other" for label "email". But I still have the problem, either encounter:

I18n::InvalidPluralizationData (translation data {:email=>"xxx"} can not be used with :count => 1):
  i18n (0.7.0) lib/i18n/backend/pluralization.rb:35:in `pluralize'
  i18n (0.7.0) lib/i18n/backend/base.rb:40:in `translate'
  i18n (0.7.0) lib/i18n.rb:158:in `block in translate'
  i18n (0.7.0) lib/i18n.rb:154:in `catch'
  i18n (0.7.0) lib/i18n.rb:154:in `translate'
  activemodel (4.2.5) lib/active_model/naming.rb:188:in `human'
  activemodel (4.2.5) lib/active_model/errors.rb:437:in `generate_message'
  activemodel (4.2.5) lib/active_model/errors.rb:449:in `normalize_message'
  activemodel (4.2.5) lib/active_model/errors.rb:300:in `add'
  ...

```

or the translation doesn't hit.

Upvotes: 2

Views: 1523

Answers (2)

Goaul
Goaul

Reputation: 1560

To anyone who gets here and wants to know easier way to figure out why rails not finds your defined translation.

To see in what paths rails are looking for translations, just add in gemfile:

gem 'i18n-debug', group: :development

Result will be in console like:

[i18n-debug] en.attributes.event_date => nil

Ref. https://github.com/fphilipe/i18n-debug

Upvotes: 0

BroiSatse
BroiSatse

Reputation: 44675

I believe you want to translate email attribute on user model. In that case you need:

xx:
  activerecord:
    attributes:
      user:
        email: "xx"

models keys are used to translate the model name, not its attributes.

Upvotes: 1

Related Questions