Class: Lit::I18nBackend

Inherits:
Object
  • Object
show all
Includes:
I18n::Backend::Simple::Implementation
Defined in:
lib/lit/i18n_backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache) ⇒ I18nBackend

Returns a new instance of I18nBackend.



9
10
11
# File 'lib/lit/i18n_backend.rb', line 9

def initialize(cache)
  @cache = cache
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



7
8
9
# File 'lib/lit/i18n_backend.rb', line 7

def cache
  @cache
end

Instance Method Details

#available_localesObject



22
23
24
# File 'lib/lit/i18n_backend.rb', line 22

def available_locales
  Lit::Locale.ordered.visible.map{|l| l.locale.to_sym }
end

#store_translations(locale, data, options = {}) ⇒ Object

Stores the given translations.

Parameters:

  • locale (String)

    the locale (ie “en”) to store translations for

  • data (Hash)

    nested key-value pairs to be added as blurbs



30
31
32
33
# File 'lib/lit/i18n_backend.rb', line 30

def store_translations(locale, data, options = {})
  super
  store_item(locale, data)
end

#translate(locale, key, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/lit/i18n_backend.rb', line 13

def translate(locale, key, options = {})
  content = super(locale, key, options.merge(:fallback => true))
  if Lit.all_translations_are_html_safe && content.respond_to?(:html_safe)
    content.html_safe
  else
    content
  end
end