Sha256: 7e0e73ed0eba62193443d37683e47543da23f2c235f0f77707fda26ba27ee136

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Formtastic
  # @private
  module I18n

    DEFAULT_SCOPE = [:formtastic].freeze
    DEFAULT_VALUES = YAML.load_file(File.expand_path("../../locale/en.yml", __FILE__))["en"]["formtastic"].freeze
    SCOPES = [
        '%{model}.%{nested_model}.%{action}.%{attribute}',
        '%{model}.%{nested_model}.%{attribute}',
        '%{nested_model}.%{action}.%{attribute}',
        '%{nested_model}.%{attribute}',
        '%{model}.%{action}.%{attribute}',
        '%{model}.%{attribute}',
        '%{attribute}'
      ]

    class << self

      def translate(*args)
        key = args.shift.to_sym
        options = args.extract_options!
        options.reverse_merge!(:default => DEFAULT_VALUES[key])
        options[:scope] = [DEFAULT_SCOPE, options[:scope]].flatten.compact
        ::I18n.translate(key, *args, **options)
      end
      alias :t :translate

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formtastic-5.0.0 lib/formtastic/i18n.rb