2010-01-20 08:41:23 -05:00
|
|
|
module AbstractController
|
2008-09-09 17:19:07 -04:00
|
|
|
module Translation
|
2013-01-20 13:15:15 -05:00
|
|
|
# Delegates to <tt>I18n#translate</tt> but also performs one additional function.
|
|
|
|
#
|
|
|
|
# It'll scope the key by the current action if the key starts
|
|
|
|
# with a period. So if you call <tt>translate(".foo")</tt> from the
|
|
|
|
# <tt>PeopleController#index</tt> action, you'll actually be calling
|
|
|
|
# <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
|
|
|
|
# to translate many keys within the same controller / action and gives you a simple framework
|
|
|
|
# for scoping them consistently. If you don't prepend the key with a period,
|
|
|
|
# nothing is converted.
|
2008-09-09 17:19:07 -04:00
|
|
|
def translate(*args)
|
2012-07-18 03:33:14 -04:00
|
|
|
key = args.first
|
|
|
|
if key.is_a?(String) && (key[0] == '.')
|
|
|
|
key = "#{ controller_path.gsub('/', '.') }.#{ action_name }#{ key }"
|
|
|
|
args[0] = key
|
|
|
|
end
|
|
|
|
|
2009-10-29 14:39:59 -04:00
|
|
|
I18n.translate(*args)
|
2008-09-09 17:19:07 -04:00
|
|
|
end
|
|
|
|
alias :t :translate
|
|
|
|
|
2013-01-20 13:15:15 -05:00
|
|
|
# Delegates to <tt>I18n.localize</tt> with no additional functionality.
|
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
|