Class: I18n::Backend::Fast
- Defined in:
- lib/i18n/backend/fast.rb,
lib/i18n/backend/fast/interpolation_compiler.rb
Defined Under Namespace
Modules: InterpolationCompiler
Constant Summary collapse
- SEPARATOR_ESCAPE_CHAR =
"\001"
Constants inherited from Base
Base::INTERPOLATION_SYNTAX_PATTERN, Base::RESERVED_KEYS
Instance Method Summary collapse
- #flattened_translations ⇒ Object
- #init_translations ⇒ Object
- #merge_translations(locale, data) ⇒ Object
- #reset_flattened_translations! ⇒ Object
- #translate(locale, key, opts = nil) ⇒ Object
Methods inherited from Base
#available_locales, #initialized?, #load_translations, #localize, #reload!, #store_translations
Instance Method Details
#flattened_translations ⇒ Object
12 13 14 |
# File 'lib/i18n/backend/fast.rb', line 12 def flattened_translations @flattened_translations ||= flatten_translations(translations) end |
#init_translations ⇒ Object
21 22 23 24 |
# File 'lib/i18n/backend/fast.rb', line 21 def init_translations super reset_flattened_translations! end |
#merge_translations(locale, data) ⇒ Object
16 17 18 19 |
# File 'lib/i18n/backend/fast.rb', line 16 def merge_translations(locale, data) super reset_flattened_translations! end |
#reset_flattened_translations! ⇒ Object
8 9 10 |
# File 'lib/i18n/backend/fast.rb', line 8 def reset_flattened_translations! @flattened_translations = nil end |
#translate(locale, key, opts = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/i18n/backend/fast.rb', line 26 def translate(locale, key, opts = nil) raise InvalidLocale.new(locale) unless locale return key.map { |k| translate(locale, k, opts) } if key.is_a?(Array) if opts count = opts[:count] scope = opts[:scope] if entry = lookup(locale, key, scope, opts[:separator]) || ((default = opts.delete(:default)) && default(locale, key, default, opts)) entry = resolve(locale, key, entry, opts) entry = pluralize(locale, entry, count) if count entry = interpolate(locale, entry, opts) entry end else resolve(locale, key, lookup(locale, key), opts) end || raise(I18n::MissingTranslationData.new(locale, key, opts)) end |