Sha256: 5f22102e1df536caeca2a3db98ace41de96f47d163b6f1bcc4ee9357fbed515a

Contents?: true

Size: 1.99 KB

Versions: 103

Compression:

Stored size: 1.99 KB

Contents

module Spaceship
  module Tunes
    class LanguageConverter
      class << self
        # Converts the iTC format (English_CA, Brazilian Portuguese) to language short codes: (en-US, de-DE)
        def from_itc_to_standard(from)
          result = mapping.find { |a| a['name'] == from }
          (result || {}).fetch('locale', nil)
        end

        # Converts the Language "UK English" to itc locale en-GB
        def from_standard_to_itc_locale(from)
          result = mapping.find { |a| a['name'] == from } || {}
          return result['itc_locale'] || result['locale']
        end

        # Converts the language short codes: (en-US, de-DE) to the iTC format (English_CA, Brazilian Portuguese)
        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

        # Get the mapping JSON parsed
        def mapping
          @languages ||= JSON.parse(File.read(File.join(Spaceship::ROOT, "lib", "assets", "languageMapping.json")))
        end

        def readable_mapping
          @readable ||= JSON.parse(File.read(File.join(Spaceship::ROOT, "lib", "assets", "languageMappingReadable.json")))
        end
      end
    end
  end
end

class String
  def to_language_code
    Spaceship::Tunes::LanguageConverter.from_itc_to_standard(self)
  end

  def to_itc_locale
    Spaceship::Tunes::LanguageConverter.from_standard_to_itc_locale(self)
  end

  def to_full_language
    Spaceship::Tunes::LanguageConverter.from_standard_to_itc(self)
  end
end

Version data entries

103 entries across 103 versions & 2 rubygems

Version Path
fastlane-2.27.0.beta.20170407010056 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.26.0 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.26.0.beta.20170406010019 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.26.0.beta.20170405010026 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.26.0.beta.20170404010022 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.25.0 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.25.0.beta.20170403010018 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.25.0.beta.20170402010035 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.25.0.beta.20170401010021 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.25.0.beta.20170331010039 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.25.0.beta.20170330225747 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0.beta.20170330010023 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0.beta.20170329010023 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0.beta.20170328010037 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0.beta.20170327010009 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0.beta.20170326010023 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.24.0.beta.20170325010032 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.23.0 spaceship/lib/spaceship/tunes/language_converter.rb
fastlane-2.23.0.beta.20170322010036 spaceship/lib/spaceship/tunes/language_converter.rb