Module: TwitterCldr::Shared::LanguageCodes

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

Constant Summary collapse

LANGUAGE_CODES_DUMP_PATH =
File.join(TwitterCldr::RESOURCES_DIR, 'shared', 'language_codes_table.dump')
NAME_STANDARD =

fake standard, mostly for internal use

:name
VALID_STANDARDS =
[:bcp_47, :iso_639_1, :iso_639_2, :iso_639_3, NAME_STANDARD]

Class Method Summary collapse

Class Method Details

.convert(code, from_and_to = {}) ⇒ Object



30
31
32
33
# File 'lib/twitter_cldr/shared/language_codes.rb', line 30

def convert(code, from_and_to = {})
  from, to = extract_from_and_to_options(from_and_to)
  resource[from].fetch(code.to_sym, {})[to]
end

.from_language(language, standard) ⇒ Object



35
36
37
# File 'lib/twitter_cldr/shared/language_codes.rb', line 35

def from_language(language, standard)
  convert(language, from: NAME_STANDARD, to: standard)
end

.languagesObject



18
19
20
# File 'lib/twitter_cldr/shared/language_codes.rb', line 18

def languages
  resource[NAME_STANDARD].keys
end

.standards_for(code, standard) ⇒ Object



43
44
45
# File 'lib/twitter_cldr/shared/language_codes.rb', line 43

def standards_for(code, standard)
  resource[validate_standard(standard)].fetch(code.to_sym, {}).keys - [NAME_STANDARD] # exclude fake NAME_STANDARD standard
end

.standards_for_language(language) ⇒ Object



47
48
49
# File 'lib/twitter_cldr/shared/language_codes.rb', line 47

def standards_for_language(language)
  standards_for(language, NAME_STANDARD)
end

.to_language(code, standard) ⇒ Object



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

def to_language(code, standard)
  convert(code, from: standard, to: NAME_STANDARD).to_s
end

.valid_code?(code, standard) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/twitter_cldr/shared/language_codes.rb', line 26

def valid_code?(code, standard)
  resource[validate_standard(standard)].has_key?(code.to_sym)
end

.valid_standard?(standard) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid_standard?(standard)
  VALID_STANDARDS.include?(standard.to_sym)
end