Module: Olelo::Locale
- Defined in:
- lib/olelo/locale.rb
Overview
Simple localization implementation
Class Attribute Summary collapse
-
.locale ⇒ Object
Returns the value of attribute locale.
Class Method Summary collapse
-
.add(locale) ⇒ void
Add locale hash.
-
.translate(key, args = {}) ⇒ String
Return translated string for key.
Class Attribute Details
.locale ⇒ Object
Returns the value of attribute locale.
8 9 10 |
# File 'lib/olelo/locale.rb', line 8 def locale @locale end |
Class Method Details
.add(locale) ⇒ void
This method returns an undefined value.
Add locale hash
A locale is a hash which maps keys to strings.
18 19 20 21 22 |
# File 'lib/olelo/locale.rb', line 18 def add(locale) @translations.update(locale[$1] || {}) if @locale =~ /^(\w+)(_|-)/ @translations.update(locale[@locale] || {}) @translations.each_value(&:freeze) end |
.translate(key, args = {}) ⇒ String
Return translated string for key
A translated string can contain variables which are substituted in this method. You have to pass an arguments hash.
35 36 37 38 39 40 41 |
# File 'lib/olelo/locale.rb', line 35 def translate(key, args = {}) if @translations[key] @translations[key] % args else args[:fallback] || "##{key}" end end |