Sha256: 1e6482a57cb035f79e3e0be0898dbd17a0fb6a1dd51e772ffe8d6c3fa3ae8cb4
Contents?: true
Size: 1.16 KB
Versions: 27
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true module Decidim # Helper that provides convenient methods to deal with translated attributes. module TranslationsHelper # Public: Returns the translation of an attribute using the current locale, # if available. # # attribute - A Hash where keys (strings) are locales, and their values are # the translation for each locale. # # Returns a String with the translation. def translated_attribute(attribute) attribute.try(:[], I18n.locale.to_s) || "" end # Public: Creates a translation for each available language in the list # given a translation key. # # key - The key to translate. # locales - A list of locales to scope the translations to. Picks up all the # available locales by default. # # Returns a Hash with the locales as keys and the translations as values. def multi_translation(key, locales = Decidim.available_locales) locales.each_with_object({}) do |locale, result| I18n.with_locale(locale) do result[locale.to_sym] = I18n.t(key) end end end module_function :multi_translation end end
Version data entries
27 entries across 27 versions & 2 rubygems