module Olelo::Locale
Simple localization implementation
Attributes
locale[RW]
Public Class Methods
add(locale)
click to toggle source
Add locale hash
A locale is a hash which maps keys to strings.
@param [Hash] Locale
hash @return [void]
# 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 = {})
click to toggle source
Return translated string for key
A translated string can contain variables which are substituted in this method. You have to pass an arguments hash.
@option args [Integer] :count if count is not 1, the key #{key}_plural is looked up instead @option args [String] :fallback Fallback string if key is not found in the locale @param [Symbol, String] key which identifies string in locale @param [Hash] args Arguments hash for string interpolation @return [String] translated string
# File lib/olelo/locale.rb, line 35 def translate(key, args = {}) if @translations[key] @translations[key] % args else args[:fallback] || "##{key}" end end