How to use rails-i18n with HAML

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

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

However, in my new.html.hamlfile, How do I link to signup?

The tutorial shows how to do this using ERB, not HAML. I tried this and it did not work:

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

Any ideas?

+5
source share
4 answers

It worked when I did this:

change en.yml

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

in .haml file

%h2= t 'registration.signup'
0
source

You should probably read the HAML link to understand how HAML works, add code to create content for the tag that you use = , as in:

%h2= t('registration.signup')
+8
source

///index.html.haml

%h2
  =t('.signup')

en.yml:

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

NB:

  • Rails YAML
  • .signup .
+3

Other comments here relay how you can do this. For what it's worth, you can also check out haml-i18n-extractor . This is a tool that helps with line interpolation, which you need to extract from templates automatically, instead of doing something manually. If you save you a ton of time.

0
source

All Articles