Sha256: 6a1a41511fbb2fde3a0624d99fde9278da5566699b5f6c501a963cd9298f1d67

Contents?: true

Size: 864 Bytes

Versions: 3

Compression:

Stored size: 864 Bytes

Contents

require 'parsi_digits'
require 'jalalidate'
require 'i18n'

module I18n
  class << self
    def localize(object, options = {})
      locale = options.delete(:locale) || config.locale
      format = options.delete(:format) || :default

      if locale == :fa and not object.nil?
        if object.respond_to? :with_parsi_digits
          object.with_parsi_digits
        elsif object.is_a? Date or object.is_a? Time
          jdate = JalaliDate.new object
          if [:default, :short, :long].include? format
            format = I18n.t("date.formats.#{format}") if object.is_a? Date
            format = I18n.t("time.formats.#{format}") if object.is_a? Time
          end
          jdate.strftime(format).with_parsi_digits
        end
      else
        config.backend.localize(locale, object, format, options)
      end
    end
    alias :l :localize
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
parsi-localize-0.2 lib/parsi_localize.rb
parsi-localize-0.1.3 lib/parsi_localize.rb
parsi-localize-0.1.2 lib/parsi_localize.rb