Sha256: 92da53b69db334d2b2120d9d10c699455e8f02ff2363a52424c19105142d553e

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'fast_gettext/mo_file'
require 'fast_gettext/storage'
require 'fast_gettext/translation'
require 'fast_gettext/translation_repository'
require 'fast_gettext/vendor/string'
require 'fast_gettext/version'

module FastGettext
  extend FastGettext::Storage
  extend FastGettext::Translation

  LOCALE_REX = /^[a-z]{2,3}$|^[a-z]{2,3}_[A-Z]{2,3}$/.freeze
  NAMESPACE_SEPARATOR = '|'
  CONTEXT_SEPARATOR = "\004"

  # helper block for changing domains
  def self.with_domain(domain)
    old_domain = FastGettext.text_domain
    FastGettext.text_domain = domain
    yield
  ensure
    FastGettext.text_domain = old_domain
  end

  def self.add_text_domain(name, options)
    translation_repositories[name] = TranslationRepository.build(name, options)
  end

  # deprecated, just a crutch to migrate to new api
  def self.allow_invalid_keys!
    eval(<<~CODE)
      class ::String
        alias :_fast_gettext_old_format_m :%
        def %(*args)
          begin
            _fast_gettext_old_format_m(*args)
          rescue KeyError
            self
          end
        end
      end
    CODE
  end

  # some repositories know where to store their locales
  def self.locale_path
    translation_repositories[text_domain].instance_variable_get(:@options)[:path]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fast_gettext-4.1.0 lib/fast_gettext.rb
fast_gettext-4.0.0 lib/fast_gettext.rb