Sha256: 0d0069e4c3cf7cb216dfd3be5d07f461c311d4b6ff7cadeeff1f66ad62f4a19d

Contents?: true

Size: 854 Bytes

Versions: 9

Compression:

Stored size: 854 Bytes

Contents

# encoding: utf-8

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}.%{action}.%{attribute}',
        '%{model}.%{nested_model}.%{attribute}',
        '%{model}.%{attribute}',
        '%{nested_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

9 entries across 9 versions & 2 rubygems

Version Path
formtastic-2.0.2 lib/formtastic/i18n.rb
formtastic-2.0.1 lib/formtastic/i18n.rb
formtastic-2.0.0 lib/formtastic/i18n.rb
formtastic-2.0.0.rc5 lib/formtastic/i18n.rb
formtastic-2.0.0.rc4 lib/formtastic/i18n.rb
formtastic-2.0.0.rc3 lib/formtastic/i18n.rb
formtastic-2.0.0.rc2 lib/formtastic/i18n.rb
formtastic-2.0.0.rc1 lib/formtastic/i18n.rb
nuatt-formtastic-0.2.3 lib/formtastic/i18n.rb