Class: Stringex::Localization::Backend::Internal

Inherits:
Base
  • Object
show all
Defined in:
lib/stringex/localization/backend/internal.rb

Constant Summary collapse

DEFAULT_LOCALE =
:en

Class Method Summary collapse

Methods inherited from Base

reset!

Class Method Details

.default_localeObject


16
17
18
# File 'lib/stringex/localization/backend/internal.rb', line 16

def default_locale
  @default_locale || DEFAULT_LOCALE
end

.default_locale=(new_locale) ⇒ Object


20
21
22
# File 'lib/stringex/localization/backend/internal.rb', line 20

def default_locale=(new_locale)
  @default_locale = @locale = new_locale.to_sym
end

.initial_translation(scope, key, locale) ⇒ Object


40
41
42
# File 'lib/stringex/localization/backend/internal.rb', line 40

def initial_translation(scope, key, locale)
  translations[locale][scope][key.to_sym]
end

.localeObject


8
9
10
# File 'lib/stringex/localization/backend/internal.rb', line 8

def locale
  @locale || default_locale
end

.locale=(new_locale) ⇒ Object


12
13
14
# File 'lib/stringex/localization/backend/internal.rb', line 12

def locale=(new_locale)
  @locale = new_locale.to_sym
end

.store_translations(locale, scope, data) ⇒ Object


36
37
38
# File 'lib/stringex/localization/backend/internal.rb', line 36

def store_translations(locale, scope, data)
  self.translations[locale.to_sym][scope.to_sym] = Hash[data.map { |k, v| [k.to_sym, v] }] # Symbolize keys
end

.translationsObject


31
32
33
34
# File 'lib/stringex/localization/backend/internal.rb', line 31

def translations
  # Set up hash like translations[:en][:transliterations]["é"]
  @translations ||= Hash.new { |k, v| k[v] = Hash.new({}) }
end

.with_locale(new_locale, &block) ⇒ Object


24
25
26
27
28
29
# File 'lib/stringex/localization/backend/internal.rb', line 24

def with_locale(new_locale, &block)
  original_locale = locale
  self.locale = new_locale
  yield
  self.locale = original_locale
end