Class: CopyTunerClient::I18nBackend
- Inherits:
-
Object
- Object
- CopyTunerClient::I18nBackend
- Includes:
- I18n::Backend::Simple::Implementation
- Defined in:
- lib/copy_tuner_client/i18n_backend.rb
Overview
I18n implementation designed to synchronize with CopyTuner.
Expects an object that acts like a Hash, responding to [], []=, and keys.
This backend will be used as the default I18n backend when the client is configured, so you will not need to instantiate this class from the application. Instead, just use methods on the I18n class.
This implementation will also load translations from locale files.
Instance Method Summary collapse
-
#available_locales ⇒ Array<String>
Returns locales available for this CopyTuner project.
-
#initialize(cache) ⇒ I18nBackend
constructor
Usually instantiated when Configuration#apply is invoked.
-
#store_translations(locale, data, options = {}) ⇒ Object
Stores the given translations.
-
#translate(locale, key, options = {}) ⇒ Object
The translated key (usually a String).
Constructor Details
#initialize(cache) ⇒ I18nBackend
Usually instantiated when Configuration#apply is invoked.
20 21 22 23 24 |
# File 'lib/copy_tuner_client/i18n_backend.rb', line 20 def initialize(cache) @cache = cache @tree_cache = nil @cache_version = nil end |
Instance Method Details
#available_locales ⇒ Array<String>
Returns locales available for this CopyTuner project.
38 39 40 41 42 43 |
# File 'lib/copy_tuner_client/i18n_backend.rb', line 38 def available_locales return @available_locales if defined?(@available_locales) cached_locales = cache.keys.map { |key| key.split('.').first } @available_locales = (cached_locales + super).uniq.map(&:to_sym) end |
#store_translations(locale, data, options = {}) ⇒ Object
Stores the given translations.
Updates will be visible in the current process immediately, and will propagate to CopyTuner during the next flush.
53 54 55 56 |
# File 'lib/copy_tuner_client/i18n_backend.rb', line 53 def store_translations(locale, data, = {}) super store_item(locale, data) end |
#translate(locale, key, options = {}) ⇒ Object
Returns the translated key (usually a String).
28 29 30 31 32 33 34 |
# File 'lib/copy_tuner_client/i18n_backend.rb', line 28 def translate(locale, key, = {}) # I18nの標準処理に任せる(内部でlookupが呼ばれる)。 # NOTE: html_safe 化は backend では行わない。.html/_html キーの html_safe 化は # ActionView の TranslationHelper(ActiveSupport::HtmlSafeTranslation)が担うため、 # backend は I18n 標準どおり素の content を返すだけにする(旧 html_escape 分岐は廃止)。 super end |