module Babylonia::HelperMethods
Helper Methods for locales @author Beat Richartz @version 0.0.2 @since 0.0.1
Public Instance Methods
Return all the available locales @return [Array] An array of symbols of all available locales
# File lib/babylonia/class_methods.rb, line 55 def available_locales evaluate_localization_option!(:available_locales) end
Return the default locale for the object @return [Symbol] The currently active locale
# File lib/babylonia/class_methods.rb, line 27 def default_locale evaluate_localization_option!(:default_locale) end
Return if a locale is theoretically available in all translated fields @return [Boolean] True if the language is available
# File lib/babylonia/class_methods.rb, line 62 def has_available_locale? locale available_locales.include?(locale.to_sym) end
Return if a translation in the language is stored in all translated fields @return [Boolean] True if a translation is stored
# File lib/babylonia/class_methods.rb, line 48 def has_locale? locale locales.include?(locale.to_sym) end
Return the currently active locale for the object @return [Symbol] The currently active locale
# File lib/babylonia/class_methods.rb, line 20 def locale evaluate_localization_option!(:locale) end
Return if the object falls back on translations @return [Boolean] if the translations fall back to the default locale
# File lib/babylonia/class_methods.rb, line 34 def locale_fallback? evaluate_localization_option!(:fallback) end
Return the missing translation placeholder @return [String] The missing translation placeholder
# File lib/babylonia/class_methods.rb, line 41 def missing_translation_placeholder field evaluate_localization_option!(:placeholder, field) end
Protected Instance Methods
# File lib/babylonia/class_methods.rb, line 72 def dump_translation_locale_hash hash YAML.dump(hash.delete_if{|k,v| translation_nil_or_empty?(v) }) end
# File lib/babylonia/class_methods.rb, line 76 def fallback_to_default_locale!(hash, translation, options) if translation_nil_or_empty?(translation) and options[:fallback] and locale_fallback? hash[default_locale] else translation end end
# File lib/babylonia/class_methods.rb, line 68 def translation_nil_or_empty? translation translation.nil? or translation.empty? end