Module: Webgen::LanguageManager
- Defined in:
- lib/webgen/languages.rb
Overview
Used for managing human languages.
Class Method Summary collapse
-
.find_language(text) ⇒ Object
Return an array of
Languageobjects whose description match the giventext. -
.language_for_code(code) ⇒ Object
Return a
Languageobject for the given language code ornilif no such object exists. -
.languages ⇒ Object
Return all available languages as a Hash.
Class Method Details
.find_language(text) ⇒ Object
Return an array of Language objects whose description match the given text.
76 77 78 |
# File 'lib/webgen/languages.rb', line 76 def self.find_language(text) languages.values.find_all {|lang| /.*#{Regexp.escape(text)}.*/i =~ lang.description}.uniq.sort end |
.language_for_code(code) ⇒ Object
Return a Language object for the given language code or nil if no such object exists.
71 72 73 |
# File 'lib/webgen/languages.rb', line 71 def self.language_for_code(code) languages[code] end |
.languages ⇒ Object
Return all available languages as a Hash. The keys are the language codes and the values are the Language objects for them.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/webgen/languages.rb', line 82 def self.languages unless defined?(@@languages) @@languages = {} started = nil data = File.readlines(__FILE__).each do |l| next if !started && (started = (l == '__END__')) data = l.chomp.split('|').collect {|f| f.empty? ? nil : f} lang = Language.new(data[0..2], data[3]) @@languages[lang.code2chars] ||= lang unless lang.code2chars.nil? @@languages[lang.code3chars] ||= lang unless lang.code3chars.nil? @@languages[lang.code3chars_alternative] ||= lang unless lang.code3chars_alternative.nil? end @@languages.freeze end @@languages end |