Sha256: d3f730f397d3e07507270f3f206773f8a198d0f0490f5d08e9c96a0886df7fd9

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

# This is a wrapper for I18n default functionality
module Remarkable
  module I18n

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

    # Set Remarkable locale (which is not necessarily the same as the application)
    def locale=(locale)
      @@locale = locale
    end

    # Get Remarkable locale (which is not necessarily the same as the application)
    def locale
      @@locale
    end

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

    # Wrapper for localization
    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

9 entries across 9 versions & 1 rubygems

Version Path
remarkable-3.0.0 lib/remarkable/i18n.rb
remarkable-3.0.1 lib/remarkable/i18n.rb
remarkable-3.0.3 lib/remarkable/i18n.rb
remarkable-3.0.4 lib/remarkable/i18n.rb
remarkable-3.0.6 lib/remarkable/i18n.rb
remarkable-3.0.7 lib/remarkable/i18n.rb
remarkable-3.0.8 lib/remarkable/i18n.rb
remarkable-3.0.5 lib/remarkable/i18n.rb
remarkable-3.0.2 lib/remarkable/i18n.rb