Sha256: af5ad0a21ed5981724244aa0f59a2792c85610763e0e7c9c531244cb8b052757

Contents?: true

Size: 1.09 KB

Versions: 438

Compression:

Stored size: 1.09 KB

Contents

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

438 entries across 438 versions & 1 rubygems

Version Path
fastlane-2.26.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.26.0.beta.20170406010019 frameit/lib/frameit/strings_parser.rb
fastlane-2.26.0.beta.20170405010026 frameit/lib/frameit/strings_parser.rb
fastlane-2.26.0.beta.20170404010022 frameit/lib/frameit/strings_parser.rb
fastlane-2.25.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.25.0.beta.20170403010018 frameit/lib/frameit/strings_parser.rb
fastlane-2.25.0.beta.20170402010035 frameit/lib/frameit/strings_parser.rb
fastlane-2.25.0.beta.20170401010021 frameit/lib/frameit/strings_parser.rb
fastlane-2.25.0.beta.20170331010039 frameit/lib/frameit/strings_parser.rb
fastlane-2.25.0.beta.20170330225747 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0.beta.20170330010023 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0.beta.20170329010023 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0.beta.20170328010037 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0.beta.20170327010009 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0.beta.20170326010023 frameit/lib/frameit/strings_parser.rb
fastlane-2.24.0.beta.20170325010032 frameit/lib/frameit/strings_parser.rb
fastlane-2.23.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.23.0.beta.20170322010036 frameit/lib/frameit/strings_parser.rb
fastlane-2.22.0 frameit/lib/frameit/strings_parser.rb