Sha256: fe3b372ce2fc0ad4b88c1873606d5af3ebe14dc16bbd69871a701a2b60ba5fca

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

module Remarkable
  # This is a wrapper for I18n default functionality.
  #
  # Remarkable shouldn't rely on I18n default locale, because it might change
  # throughout tests. So it's Remarkable responsibility to hold its own locale
  # and send it to I18n.
  #
  module I18n

    # Add locale files to I18n and to load path, if it exists.
    #
    # == Examples
    #
    #   Remarkable.add_locale "path/to/locale"
    #
    def add_locale(*locales)
      ::I18n.backend.load_translations *locales
      ::I18n.load_path += locales if ::I18n.respond_to?(:load_path)
    end

    # Set Remarkable own locale.
    #
    # == Examples
    #
    #   Remarkable.locale = :en
    #
    def locale=(locale)
      @@locale = locale
    end

    # Get Remarkable own locale.
    #
    # == Examples
    #
    #   Remarkable.locale = :en
    #   Remarkable.locale #=> :en
    #
    def locale
      @@locale
    end

    # Wrapper for I18n.translate
    #
    def translate(string, options = {})
      ::I18n.translate string, { :locale => @@locale }.merge(options)
    end
    alias :t :translate

    # Wrapper for I18n.localize
    #
    def localize(object, options = {})
      ::I18n.localize object, { :locale => @@locale }.merge(options)
    end
    alias :l :localize

  end
end

# Load I18n
RAILS_I18N = Object.const_defined?(:I18n) unless Object.const_defined?(:RAILS_I18N) # Rails >= 2.2

unless RAILS_I18N
  begin
    require 'i18n'
  rescue LoadError
    require 'rubygems'
    # TODO Move to i18n gem as soon as it gets updated
    gem 'svenfuchs-i18n'
    require 'i18n'
  end

  # Set default locale
  ::I18n.default_locale = :en
end

Remarkable.extend Remarkable::I18n
Remarkable.locale = :en

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
remarkable-3.1.7 lib/remarkable/i18n.rb
remarkable-3.1.8 lib/remarkable/i18n.rb
remarkable-3.0.9 lib/remarkable/i18n.rb
remarkable-3.0.10 lib/remarkable/i18n.rb
remarkable-3.1.4 lib/remarkable/i18n.rb
remarkable-3.1.5 lib/remarkable/i18n.rb
remarkable-3.1.6 lib/remarkable/i18n.rb
remarkable-3.1.2 lib/remarkable/i18n.rb
remarkable-3.1.0 lib/remarkable/i18n.rb
remarkable-3.1.1 lib/remarkable/i18n.rb
remarkable-3.1.3 lib/remarkable/i18n.rb