Class: CopycopterClient::I18nBackend
- Inherits:
-
Object
- Object
- CopycopterClient::I18nBackend
- Includes:
- I18n::Backend::Simple::Implementation
- Defined in:
- lib/copycopter_client/i18n_backend.rb
Overview
I18n implementation designed to synchronize with Copycopter.
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 availabile for this Copycopter 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
Translates the given local and key.
Constructor Details
#initialize(cache) ⇒ I18nBackend
Usually instantiated when Configuration#apply is invoked.
18 19 20 |
# File 'lib/copycopter_client/i18n_backend.rb', line 18 def initialize(cache) @cache = cache end |
Instance Method Details
#available_locales ⇒ Array<String>
Returns locales availabile for this Copycopter project.
36 37 38 39 |
# File 'lib/copycopter_client/i18n_backend.rb', line 36 def available_locales cached_locales = cache.keys.map { |key| key.split('.').first } (cached_locales + super).uniq.map { |locale| locale.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 Copycopter during the next flush.
49 50 51 52 |
# File 'lib/copycopter_client/i18n_backend.rb', line 49 def store_translations(locale, data, = {}) super store_item(locale, data) end |
#translate(locale, key, options = {}) ⇒ Object
Translates the given local and key. See the I18n API documentation for details.
25 26 27 28 29 30 31 32 |
# File 'lib/copycopter_client/i18n_backend.rb', line 25 def translate(locale, key, = {}) content = super(locale, key, .merge(:fallback => true)) if content.respond_to?(:html_safe) content.html_safe else content end end |