Module: I18n::Backend::Simple::Implementation
- Includes:
- Base
- Included in:
- I18n::Backend::Simple
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb
Constant Summary
Constants included from Transliterator
Transliterator::DEFAULT_REPLACEMENT_CHAR
Instance Method Summary collapse
-
#available_locales ⇒ Object
Get available locales from the translations hash.
- #eager_load! ⇒ Object
- #initialized? ⇒ Boolean
-
#reload! ⇒ Object
Clean up translations hash and set initialized to false on reload!.
-
#store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
Stores translations for the given locale in memory.
- #translations(do_init: false) ⇒ Object
Methods included from Base
#exists?, #load_translations, #localize, #translate
Methods included from Transliterator
Instance Method Details
#available_locales ⇒ Object
Get available locales from the translations hash
46 47 48 49 50 51 52 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb', line 46 def available_locales init_translations unless initialized? translations.inject([]) do |locales, (locale, data)| locales << locale unless data.size <= 1 && (data.empty? || data.has_key?(:i18n)) locales end end |
#eager_load! ⇒ Object
61 62 63 64 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb', line 61 def eager_load! init_translations unless initialized? super end |
#initialized? ⇒ Boolean
25 26 27 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb', line 25 def initialized? @initialized ||= false end |
#reload! ⇒ Object
Clean up translations hash and set initialized to false on reload!
55 56 57 58 59 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb', line 55 def reload! @initialized = false @translations = nil super end |
#store_translations(locale, data, options = EMPTY_HASH) ⇒ Object
Stores translations for the given locale in memory. This uses a deep merge for the translations hash, so existing translations will be overwritten by new ones only at the deepest level of the hash.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb', line 33 def store_translations(locale, data, = EMPTY_HASH) if I18n.enforce_available_locales && I18n.available_locales_initialized? && !I18n.locale_available?(locale) return data end locale = locale.to_sym translations[locale] ||= Concurrent::Hash.new data = Utils.deep_symbolize_keys(data) unless .fetch(:skip_symbolize_keys, false) Utils.deep_merge!(translations[locale], data) end |
#translations(do_init: false) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/i18n-1.12.0/lib/i18n/backend/simple.rb', line 66 def translations(do_init: false) # To avoid returning empty translations, # call `init_translations` init_translations if do_init && !initialized? @translations ||= Concurrent::Hash.new { |h, k| h[k] = Concurrent::Hash.new } end |