Module: TwitterCldr::Shared::Languages

Defined in:
lib/twitter_cldr/shared/languages.rb

Class Method Summary collapse

Class Method Details

.allObject


12
13
14
# File 'lib/twitter_cldr/shared/languages.rb', line 12

def all
  all_for(TwitterCldr.get_locale)
end

.all_for(code) ⇒ Object


16
17
18
19
20
# File 'lib/twitter_cldr/shared/languages.rb', line 16

def all_for(code)
  get_resource(TwitterCldr.convert_locale(code.to_sym))[:languages]
rescue
  {}
end

.from_code(code) ⇒ Object


22
23
24
# File 'lib/twitter_cldr/shared/languages.rb', line 22

def from_code(code)
  from_code_for_locale(code, TwitterCldr.get_locale)
end

.from_code_for_locale(code, locale = TwitterCldr.get_locale) ⇒ Object


26
27
28
29
30
# File 'lib/twitter_cldr/shared/languages.rb', line 26

def from_code_for_locale(code, locale = TwitterCldr.get_locale)
  get_resource(TwitterCldr.convert_locale(locale.to_sym))[:languages][TwitterCldr.convert_locale(code.to_sym)]
rescue
  nil
end

.translate_language(language, source_locale = :en, dest_locale = TwitterCldr.get_locale) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/twitter_cldr/shared/languages.rb', line 32

def translate_language(language, source_locale = :en, dest_locale = TwitterCldr.get_locale)
  source_locale = TwitterCldr.convert_locale(source_locale.to_sym)
  lang_code = get_resource(source_locale)[:languages].select { |key, val| val.downcase == language.downcase }.flatten.first

  if lang_code
    dest_locale = TwitterCldr.convert_locale(dest_locale.to_sym)
    get_resource(dest_locale)[:languages][lang_code.to_sym]
  else
    nil
  end
rescue
  nil
end