Sha256: 212d191a1b50606143f08d820403c310a71bd1e60f8c17f8194307220f2525a9

Contents?: true

Size: 968 Bytes

Versions: 7

Compression:

Stored size: 968 Bytes

Contents

module Formtastic
  module I18n
    
    DEFAULT_SCOPE = [:formtastic].freeze
    DEFAULT_VALUES = {
        :required       => 'required',
        :yes            => 'Yes',
        :no             => 'No',
        :create         => 'Create %{model}',
        :update         => 'Update %{model}'
      }.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

7 entries across 7 versions & 4 rubygems

Version Path
formtastic-1.1.0 lib/formtastic/i18n.rb
formtastic-1.1.0.beta lib/formtastic/i18n.rb
sensis-formtastic-rails3-1.d4e5326 lib/formtastic/i18n.rb
techthumb-formtastic-1.rails3.sha lib/formtastic/i18n.rb
formtastic-rails3-1.0.0.beta3 lib/formtastic/i18n.rb
formtastic-rails3-0.9.10.1 lib/formtastic/i18n.rb
formtastic-rails3-0.9.10.0 lib/formtastic/i18n.rb