podemos-info/census

View on GitHub
app/helpers/translations_helper.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

# 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) || attribute.try(:[], Settings.regional.locales.default) || ""
  end
end