Search code examples
ruby-on-railsruby-on-rails-3internationalizationrails-i18n

Rails: i18n, variable gets printed if translation is not there


I am facing a weird problem. In my rails 3 app I am supporting internationalization with english and french. Here in my template I wrote something like this

<%= t "Hi %{person}!", :person => "Simpson" %>

When I set locale as french everything works fine, since it has got translation for this but when I set locale as english then it gives output as

Hi %{person}!

in my browser. When I add translation to en.yml, it works fine. I don't understand why there is need to add translation in en.yml for this. Moreover I don't want this to happen, is there any work around for this?

Thanks


Solution

  • The first argument givent to the t method should be a key, so your view should have something like this :

    <%= t :greetings, :person => "Simpson" %>
    

    Your config/locales/en.yml would look like this :

    en:
      greetings: Hi %{person}
    

    and your config/locales/fr.yml something like this :

    fr:
      greetings: Bonjour %{person}