Class: Spaceship::Tunes::LanguageConverter

Inherits:
Object
  • Object
show all
Defined in:
spaceship/lib/spaceship/tunes/language_converter.rb

Class Method Summary collapse

Class Method Details

.from_itc_readable_to_itc(from) ⇒ Object

Converts the language “UK English” (user facing) to “English_UK” (value)



26
27
28
29
30
31
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 26

def from_itc_readable_to_itc(from)
  readable_mapping.each do |key, value|
    return key if value == from
  end
  nil
end

.from_itc_to_itc_readable(from) ⇒ Object

Converts the language “English_UK” (value) to “UK English” (user facing)



34
35
36
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 34

def from_itc_to_itc_readable(from)
  readable_mapping[from]
end

.from_itc_to_standard(from) ⇒ Object

Converts the iTC format (English_CA, Brazilian Portuguese) to language short codes: (en-US, de-DE)



8
9
10
11
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 8

def from_itc_to_standard(from)
  result = mapping.find { |a| a['name'] == from }
  (result || {}).fetch('locale', nil)
end

.from_standard_to_itc(from) ⇒ Object

Converts the language short codes: (en-US, de-DE) to the iTC format (English_CA, Brazilian Portuguese)



20
21
22
23
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 20

def from_standard_to_itc(from)
  result = mapping.find { |a| a['locale'] == from || (a['alternatives'] || []).include?(from) }
  (result || {}).fetch('name', nil)
end

.from_standard_to_itc_locale(from) ⇒ Object

Converts the Language “UK English” to itc locale en-GB



14
15
16
17
# File 'spaceship/lib/spaceship/tunes/language_converter.rb', line 14

def from_standard_to_itc_locale(from)
  result = mapping.find { |a| a['name'] == from } || {}
  return result['itc_locale'] || result['locale']
end