netwire
netwire

Reputation: 7215

How to use rails-i18n with HAML

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?

Upvotes: 8

Views: 5904

Answers (4)

Maur&#237;cio Linhares
Maur&#237;cio Linhares

Reputation: 40333

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')

Upvotes: 10

Shai
Shai

Reputation: 1509

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.

Upvotes: -1

Vadym Tyemirov
Vadym Tyemirov

Reputation: 8833

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

Upvotes: 3

netwire
netwire

Reputation: 7215

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'

Upvotes: 0

Related Questions