Class: Stringex::Localization::Backend::Internal
- Defined in:
- lib/stringex/localization/backend/internal.rb
Constant Summary collapse
- DEFAULT_LOCALE =
:en
Class Method Summary collapse
- .default_locale ⇒ Object
- .default_locale=(new_locale) ⇒ Object
- .initial_translation(scope, key, locale) ⇒ Object
- .locale ⇒ Object
- .locale=(new_locale) ⇒ Object
- .store_translations(locale, scope, data) ⇒ Object
- .translations ⇒ Object
- .with_locale(new_locale, &block) ⇒ Object
Methods inherited from Base
Class Method Details
.default_locale ⇒ Object
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 |
.locale ⇒ Object
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 |
.translations ⇒ Object
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 |