Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 951 Bytes

rails_i18n_internationalization.md

File metadata and controls

62 lines (45 loc) · 951 Bytes

http://edgeguides.rubyonrails.org/i18n.html

pick / Change format type

 helper.l Time.now.to_date
 => "2014-08-19"
 
 helper.l Time.now.to_date, format: :long
 # => "August 19, 2014" 

Get current locale (language)

I18n.locale

translate array

# app/model/validation.rb
class Validation
  STATUSES = %w(Pass Fail)
end  
# config/locales/en.yml
en:
  something_something:
    validation
      statuses: 
        Pass: 'yes'
        Fail: 'NOOO!'
= t(Validation::STATUSES, scope: 'something_something:validation:statuses'

will render ['yes', 'NOOO!']

source: http://stackoverflow.com/questions/12341231/rails-how-to-i18n-an-array-of-strings

Variables

... or sprintf syntax

-# app/views/home/index.html.erb
=t 'foo.greet_username', user: "Bill", message: "Goodbye"
# config/locales/en.yml
en:
  foo
    greet_username: "%{message}, %{user}!"