Search code examples
ruby-on-railsinternationalizationformtastic

Why are my formtastic translations not working


Translations seem to be my greatest enemy:( I have a nice Formtastic form, and a yaml translation file. I've set the translation in the config/application.rb like this:

config.i18n.available_locales = :nl
config.i18n.default_locale = :nl

and a before_filter method in application_controller.rb like this:

before_filter :set_locale

def set_locale
  session[:locale] = params[:locale] unless params[:locale].nil?
  I18n.locale = session[:locale] || I18n.default_locale
end

My form looks like this (it's written in haml):

= semantic_form_for Ad.new do |f|       
  .holder
    = f.inputs do
      = f.input :name

    = f.inputs do
      = f.input :reason

and finaly my nl.yml looks like this:

nl:
  formtastic:
    titles:
      ads:
        reason: "Waarom verkoop je het?"
    labels:
      ads:
        reason: "Waarom verkoop je het?"
    hints:
      ads:
        reason: "Waarom verkoop je het?"
    placeholders:
      ads:
        reason: "Waarom verkoop je het?"

As you can see I've added the same translation to all these keys Formtastic provides but none show up, the label remains Reason and there is no placeholder text. For as far as I can tell I've done exactly what the Formtastic readme prescribes. I'm using formtastic (2.2.1) with rails (3.2.8). If I add activerecord translations to the nl.yml the label does get translated. Why don't the formtastic translations work?


Solution

  • This is a little lame, but the problem turned out to be in the ads part. I shouldn't have pluralized ad. This works fine:

    nl:
      formtastic:
        titles:
          ad: // Mind the difference here: no 's'
            reason: "Waarom verkoop je het?"
        labels:
          ad:
            reason: "Waarom verkoop je het?"
        hints:
          ad:
            reason: "Waarom verkoop je het?"
        placeholders:
          ad:
            reason: "Waarom verkoop je het?"