Sha256: 7619bfe8a656ab163fe06ddcab466ed085301bd604395d1ceef3863a0093f4c1

Contents?: true

Size: 1.13 KB

Versions: 28

Compression:

Stored size: 1.13 KB

Contents

require_relative 'module'

module Frameit
  # This class will parse the .string files
  class StringsParser
    def self.parse(path)
      UI.user_error!("Couldn't find strings file at path '#{path}'") unless File.exist?(path)
      UI.user_error!("Must be .strings file, only got '#{path}'") unless path.end_with?(".strings")

      result = {}

      # A .strings file is UTF-16 encoded. We only want to deal with UTF-8
      content = `iconv -f UTF-16 -t UTF-8 '#{path}' 2>&1`

      content.split("\n").each_with_index do |line, index|
        begin
          # We don't care about comments and empty lines
          if line.start_with?('"')
            key = line.match(/"(.*)" \= /)[1]
            value = line.match(/ \= "(.*)"/)[1]

            result[key] = value
          end
        rescue => ex
          UI.error("Error parsing #{path} line #{index + 1}: '#{line}'")
          UI.verbose("#{ex.message}\n#{ex.backtrace.join('\n')}")
        end
      end

      if result.empty?
        UI.error("Empty parsing result for #{path}. Please make sure the file is valid and UTF16 Big-endian encoded")
      end

      result
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
fastlane-2.79.0.beta.20180129010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.79.0.beta.20180128010002 frameit/lib/frameit/strings_parser.rb
fastlane-2.79.0.beta.20180127010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.79.0.beta.20180126010002 frameit/lib/frameit/strings_parser.rb
fastlane-2.79.0.beta.20180125010002 frameit/lib/frameit/strings_parser.rb
fastlane-2.79.0.beta.20180124010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.79.0.beta.20180123010002 frameit/lib/frameit/strings_parser.rb
fastlane-2.78.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.78.0.beta.20180122010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.78.0.beta.20180121010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.78.0.beta.20180120010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.78.0.beta.20180119010003 frameit/lib/frameit/strings_parser.rb
fastlane-2.77.1 frameit/lib/frameit/strings_parser.rb
fastlane-2.77.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.77.0.beta.20180118010004 frameit/lib/frameit/strings_parser.rb
fastlane-2.77.0.beta.20180117010004 frameit/lib/frameit/strings_parser.rb
fastlane-2.76.1 frameit/lib/frameit/strings_parser.rb
fastlane-2.76.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.76.0.beta.20180116010004 frameit/lib/frameit/strings_parser.rb
fastlane-2.76.0.beta.20180115010004 frameit/lib/frameit/strings_parser.rb