Sha256: 323b50ba12afe7a1bdbd5e83e5192895225cd8da95cf07e880ed29a866a48b29

Contents?: true

Size: 1.09 KB

Versions: 21

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}'`

      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

21 entries across 21 versions & 2 rubygems

Version Path
fastlane-2.9.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.8.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.7.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.6.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.5.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.4.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.3.1 frameit/lib/frameit/strings_parser.rb
fastlane-2.3.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.2.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.1.3 frameit/lib/frameit/strings_parser.rb
fastlane-2.1.2 frameit/lib/frameit/strings_parser.rb
fastlane-2.1.1 frameit/lib/frameit/strings_parser.rb
frameit-4.0.0 lib/frameit/strings_parser.rb
fastlane-2.1.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.0.5 frameit/lib/frameit/strings_parser.rb
fastlane-2.0.4 frameit/lib/frameit/strings_parser.rb
fastlane-2.0.3 frameit/lib/frameit/strings_parser.rb
fastlane-2.0.2 frameit/lib/frameit/strings_parser.rb
fastlane-2.0.1 frameit/lib/frameit/strings_parser.rb
frameit-3.0.0 lib/frameit/strings_parser.rb