Sha256: a0aee77b5f21100d15961b65b7d6846cdf112b43c82cd47d180edc02b9b1ea71

Contents?: true

Size: 1.29 KB

Versions: 25

Compression:

Stored size: 1.29 KB

Contents

module Account::LocaleHelper
  def current_locale
    current_user.locale || current_team.locale || "en"
  end

  # as of now, we only calculate a possessive version of nouns in english.
  # if you're aware of another language where we can do this, please don't hesitate to reach out!
  def possessive_string(string)
    [:en].include?(I18n.locale) ? string.possessive : string
  end

  def model_locales(model)
    name = model.label_string.presence
    return {} unless name

    hash = {}
    prefix = model.class.name.split("::").last.underscore
    hash[:"#{prefix}_name"] = name
    hash[:"#{prefix.pluralize}_possessive"] = possessive_string(name)

    hash
  end

  def models_locales(*models)
    hash = {}
    models.compact.each do |model|
      hash.merge! model_locales(model)
    end
    hash
  end

  # this is a bit scary, no?
  def account_controller?
    controller.class.name.match(/^Account::/)
  end

  def t(key, options = {})
    if account_controller?
      # give preference to the options they've passed in.
      options = models_locales(@child_object, @parent_object).merge(options)
    end
    super(key, options)
  end

  # like 't', but if the key isn't found, it returns nil.
  def ot(key, options = {})
    t(key, options)
  rescue I18n::MissingTranslationData => _
    nil
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
bullet_train-1.0.30 app/helpers/account/locale_helper.rb
bullet_train-1.0.29 app/helpers/account/locale_helper.rb
bullet_train-1.0.28 app/helpers/account/locale_helper.rb
bullet_train-1.0.27 app/helpers/account/locale_helper.rb
bullet_train-1.0.26 app/helpers/account/locale_helper.rb
bullet_train-1.0.25 app/helpers/account/locale_helper.rb
bullet_train-1.0.24 app/helpers/account/locale_helper.rb
bullet_train-1.0.23 app/helpers/account/locale_helper.rb
bullet_train-1.0.22 app/helpers/account/locale_helper.rb
bullet_train-1.0.21 app/helpers/account/locale_helper.rb
bullet_train-1.0.20 app/helpers/account/locale_helper.rb
bullet_train-1.0.19 app/helpers/account/locale_helper.rb
bullet_train-1.0.18 app/helpers/account/locale_helper.rb
bullet_train-1.0.17 app/helpers/account/locale_helper.rb
bullet_train-1.0.16 app/helpers/account/locale_helper.rb
bullet_train-1.0.15 app/helpers/account/locale_helper.rb
bullet_train-1.0.14 app/helpers/account/locale_helper.rb
bullet_train-1.0.13 app/helpers/account/locale_helper.rb
bullet_train-1.0.12 app/helpers/account/locale_helper.rb
bullet_train-1.0.11 app/helpers/account/locale_helper.rb