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)



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

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)



32
33
34
# File 'lib/spaceship/tunes/language_converter.rb', line 32

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)



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

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



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

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