stergosz
stergosz

Reputation: 5860

ruby on rails how to call locale message to view

This is my config/locales/en.yml file:

# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
  hello: "Hello world"
  signup_title: "Sign Up for Test"

what i use in view to call a message from this file(probably incorrectly used)

<h1><%= en.signup_title %></h1>

and of course i get some errors

undefined local variable or method `en' for #<#<Class:0x007fd14d4f4338>:0x007fd14d501fb0>

so how can i get the message value without any errors?

Upvotes: 1

Views: 1331

Answers (2)

squiter
squiter

Reputation: 5761

Use this:
<h1><%= t(:signup_title) %></h1>
Read more in: http://guides.rubyonrails.org/i18n.html#the-public-i18n-api

Upvotes: 2

Ismael
Ismael

Reputation: 16730

<h1><%= t 'signup_title' %></h1>

t is an alias method for the translate method

<h1><%= translate 'signup_title' %></h1>

http://guides.rubyonrails.org/i18n.html#the-public-i18n-api

For different locations see http://guides.rubyonrails.org/i18n.html#setting-and-passing-the-locale

Upvotes: 1

Related Questions