Class: Spaceship::Tunes::LanguageConverter

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

Class Method Summary collapse

Class Method Details

.from_itc_readable_to_itc(from) ⇒ Object

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



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

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 langauge “English_UK” (value) to “UK English” (user facing)



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

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)



6
7
8
9
# File 'lib/spaceship/tunes/language_converter.rb', line 6

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)



12
13
14
15
# File 'lib/spaceship/tunes/language_converter.rb', line 12

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