lib/spaceship/tunes/language_converter.rb in spaceship-0.2.0 vs lib/spaceship/tunes/language_converter.rb in spaceship-0.3.0
- old
+ new
@@ -12,10 +12,23 @@
def from_standard_to_itc(from)
result = mapping.find { |a| a['locale'] == from || (a['alternatives'] || []).include?(from) }
(result || {}).fetch('name', nil)
end
+ # Converts the langauge "UK English" (user facing) to "English_UK" (value)
+ def from_itc_readable_to_itc(from)
+ readable_mapping.each do |key, value|
+ return key if value == from
+ end
+ nil
+ end
+
+ # Converts the langauge "English_UK" (value) to "UK English" (user facing)
+ def from_itc_to_itc_readable(from)
+ readable_mapping[from]
+ end
+
private
# Path to the gem to fetch resoures
def spaceship_gem_path
if Gem::Specification::find_all_by_name('spaceship').any?
return Gem::Specification.find_by_name('spaceship').gem_dir
@@ -25,9 +38,13 @@
end
# Get the mapping JSON parsed
def mapping
@languages ||= JSON.parse(File.read(File.join(spaceship_gem_path, "lib", "assets", "languageMapping.json")))
+ end
+
+ def readable_mapping
+ @readable ||= JSON.parse(File.read(File.join(spaceship_gem_path, "lib", "assets", "languageMappingReadable.json")))
end
end
end
end
end
\ No newline at end of file