2010-01-20 08:41:23 -05:00
|
|
|
module AbstractController
|
2008-09-09 17:19:07 -04:00
|
|
|
module Translation
|
2013-01-20 19:47:41 -05:00
|
|
|
# Delegates to <tt>I18n.translate</tt>. Also aliased as <tt>t</tt>.
|
2013-01-20 13:15:15 -05:00
|
|
|
#
|
2013-01-20 19:47:41 -05:00
|
|
|
# When the given key starts with a period, it will be scoped by the current
|
|
|
|
# controller and action. So if you call <tt>translate(".foo")</tt> from
|
|
|
|
# <tt>PeopleController#index</tt>, it will convert the call to
|
2013-01-20 13:15:15 -05:00
|
|
|
# <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
|
2013-01-20 19:47:41 -05:00
|
|
|
# to translate many keys within the same controller / action and gives you a
|
|
|
|
# simple framework for scoping them consistently.
|
2013-08-07 04:33:28 -04:00
|
|
|
def translate(key, options = {})
|
|
|
|
if key.to_s.first == '.'
|
2013-10-22 10:14:50 -04:00
|
|
|
path = controller_path.tr('/', '.')
|
|
|
|
defaults = [:"#{path}#{key}"]
|
|
|
|
defaults << options[:default] if options[:default]
|
|
|
|
options[:default] = defaults
|
|
|
|
key = "#{path}.#{action_name}#{key}"
|
2012-07-18 03:33:14 -04:00
|
|
|
end
|
2013-08-07 04:33:28 -04:00
|
|
|
I18n.translate(key, options)
|
2008-09-09 17:19:07 -04:00
|
|
|
end
|
|
|
|
alias :t :translate
|
|
|
|
|
2013-01-20 19:47:41 -05:00
|
|
|
# Delegates to <tt>I18n.localize</tt>. Also aliased as <tt>l</tt>.
|
2008-09-09 17:19:07 -04:00
|
|
|
def localize(*args)
|
2009-10-29 14:39:59 -04:00
|
|
|
I18n.localize(*args)
|
2008-09-09 17:19:07 -04:00
|
|
|
end
|
|
|
|
alias :l :localize
|
|
|
|
end
|
2012-07-18 03:33:14 -04:00
|
|
|
end
|