ActionView::Helpers::TranslationHelper

Alias: l

def localize(object, **options)

Description

Converts a date or time to a string in a translated format.

Arguments

Changing a value updates the ERB and HTML.

A Date, DateTime or Time. Anything else (including nil) raises I18n::ArgumentError. For nil, though, the :default value is returned if given.
= :default
Accepts:
  • A symbol: looks up the key with this name in the date.formats translation (for a Date) or time.formats (for anything with a time), and passes its value to strftime (for :long, the value of date.formats.long). If there is no such key, raises I18n::MissingTranslationData unless :default is given.
  • A string: used as a strftime format.
In either format, %a, %A, %b and %B become the translated day and month names (date.abbr_day_names, etc.), %p becomes the time.am or time.pm translation in uppercase, and %P in lowercase. This site's Japanese translations are the same as rails-i18n, and the English ones are Rails' own.
options= {}
Uses the translations for this locale instead of the current one.
"-"
Used instead when the object argument is nil, or when there is no translation for a symbol format. In the latter case, a string is used as a strftime format (%Y gives 2026).
Other options (scope, etc.) are passed to I18n's localize as is. They do not become HTML attributes.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview