Module: I18n
- Defined in:
- lib/i18n/bamboo.rb,
lib/i18n/bamboo/railtie.rb,
lib/i18n/bamboo/version.rb,
lib/i18n/bamboo/fertilizer.rb,
lib/i18n/bamboo/fertilizer.rb
Defined Under Namespace
Modules: Bamboo
Class Method Summary collapse
-
.localize(object, options = {}) ⇒ Object
(also: l)
Public: Unless overridden, translates using the longest localized value from among all available locales.
- .original_localize ⇒ Object
- .original_translate ⇒ Object
-
.translate(*args) ⇒ Object
(also: t)
Public: Unless overridden, translates using the longest translation from among all available locales.
Class Method Details
.localize(object, options = {}) ⇒ Object Also known as: l
Public: Unless overridden, translates using the longest localized value from among all available locales.
object - see goo.gl/bbXILw for original method argument doc options - see goo.gl/bbXILw for original method argument doc. This Hash can can contain the
the following custom key:
:force_default_behavior - Boolean that determines whether or not to force the default localize
behavior
Returns the longest localized String.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/i18n/bamboo/fertilizer.rb', line 50 def localize(object, = {}) # Fall back to the default localize behavior if the :force_default_behavior is true return original_localize(object, ) if .delete(:force_default_behavior) localized_values = [] available_locales.each do |locale| = .merge(locale: locale) localized_values << original_localize(object, ) end localized_values.max end |
.original_localize ⇒ Object
9 |
# File 'lib/i18n/bamboo/fertilizer.rb', line 9 alias_method :original_localize, :localize |
.original_translate ⇒ Object
8 |
# File 'lib/i18n/bamboo/fertilizer.rb', line 8 alias_method :original_translate, :translate |
.translate(*args) ⇒ Object Also known as: t
Public: Unless overridden, translates using the longest translation from among all available locales.
*args - see goo.gl/vSpFKl for original method argument doc options - The final argument can optionally be a Hash of options
:force_default_behavior - Boolean that determines whether or not to force the default translate
behavior
Returns the longest translated String.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/i18n/bamboo/fertilizer.rb', line 19 def translate(*args) # Fall back to the default translate behavior if the :force_default_behavior is true force_current_locale = args.last.is_a?(Hash) ? args.pop.delete(:force_default_behavior) : false return original_translate(*args) if force_current_locale translations = [] available_locales.each do |locale| args_copy = args.dup if args_copy.last.is_a?(Hash) args_copy.last.merge!(locale: locale) else args_copy << {locale: locale} end translations << original_translate(*args_copy) end translations.max end |