Module: MI18n
- Defined in:
- lib/merb_babel/m_i18n.rb
Class Method Summary collapse
- .lookup(options) ⇒ Object
- .lookup_with_full_locale(keys, language, country) ⇒ Object
- .lookup_with_hash(keys, l_hash) ⇒ Object
- .lookup_with_language(keys, language) ⇒ Object
Class Method Details
.lookup(options) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/merb_babel/m_i18n.rb', line 3 def self.lookup() keys = [[:keys].map{|key| key.to_s}].flatten language = [:language] country = [:country] raise ArgumentError, "You need to pass a language reference" unless language raise ArgumentError, "You need to pass a localization key" if keys.empty? raise ArgumentError, "language: #{language} not found" unless ML10n.localizations[language] full_location = nil full_location = lookup_with_full_locale(keys, language, country) if country if full_location return full_location else return lookup_with_language(keys, language) || keys.last end end |
.lookup_with_full_locale(keys, language, country) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/merb_babel/m_i18n.rb', line 27 def self.lookup_with_full_locale(keys, language, country) if ML10n.localizations.has_key?(language) ML10n.localizations[language].has_key?(country) ? lookup_with_hash(keys, ML10n.localizations[language][country]) : nil else nil end end |
.lookup_with_hash(keys, l_hash) ⇒ Object
36 37 38 |
# File 'lib/merb_babel/m_i18n.rb', line 36 def self.lookup_with_hash(keys, l_hash) keys.inject(l_hash){|h,k| h[k] rescue nil} end |
.lookup_with_language(keys, language) ⇒ Object
23 24 25 |
# File 'lib/merb_babel/m_i18n.rb', line 23 def self.lookup_with_language(keys, language) lookup_with_hash(keys, ML10n.localizations[language]) end |