Search code examples
ruby-on-railsrubylocale

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?


Solution

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