Sha256: fd1ca8e0532b378acbeac012a9e33ef9b9e1189a02e24b458f9353c226d50eae

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

# coding: utf-8
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

1 entries across 1 versions & 1 rubygems

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