8

I went through http://guides.rubyonrails.org/i18n.html and set up my en.yml file:

en:
  test:
    welcome: Welcome!!!
  registration:
    signup: Sign up for an invite!!

However, in my new.html.haml file, How do I reference signup?

The tutorial only shows how to do so using ERB, not HAML. I tried this and it didn't work:

%h2 <%=t :registration.signup %>

Any ideas?

netwire
  • 7,108
  • 12
  • 52
  • 86

4 Answers4

10

You should probably read the HAML reference to understand how HAML works. To add code to generate content for a tag, you use =, as in:

%h2= t('registration.signup')
mbds
  • 89
  • 1
  • 6
Maurício Linhares
  • 39,901
  • 14
  • 121
  • 158
3

app/views/registration/index.html.haml

%h2
  =t('.signup')

en.yml:

en:
  registration:
    index:
      signup: Sign up for an invite!!

NB:

  1. Rails path to the view must match YAML path to the symbol
  2. There is a dot before .signup. Read more about lazy lookups
Vadym Tyemirov
  • 8,288
  • 4
  • 42
  • 38
0

It worked once I did this:

change en.yml

  registration:
    signup: "Sign up for an invite to join CorkLabs!!!"

in .haml file

%h2= t 'registration.signup'
netwire
  • 7,108
  • 12
  • 52
  • 86
-1

Other comments here relay how you can do this. For what it's worth though, you can also check out haml-i18n-extractor. It's a tool that helps with the string interpolation you need to extract from the templates automatically instead of needing to do things by hand. Should save you a bunch of time.

Shai
  • 1,281
  • 9
  • 7