1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# 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
|