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.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(code)[: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.locale)
end

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


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

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

.is_rtl?(locale) ⇒ Boolean

Returns:

  • (Boolean)

39
40
41
42
# File 'lib/twitter_cldr/shared/languages.rb', line 39

def is_rtl?(locale)
  locale = TwitterCldr.convert_locale(locale)
  TwitterCldr.get_locale_resource(locale, :layout)[locale][:layout][:orientation][:character_order] == "right-to-left"
end

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


32
33
34
35
36
37
# File 'lib/twitter_cldr/shared/languages.rb', line 32

def translate_language(language, source_locale = :en, dest_locale = TwitterCldr.locale)
  lang_code = get_resource(source_locale)[:languages].detect { |_, val| val.downcase == language.downcase }.first
  get_resource(dest_locale)[:languages][lang_code] if lang_code
rescue
  nil
end