Sha256: f3787eead38eca2360ca2338c1cdd5bab6a16ce5ccb0afc5c2f35ffe1baa0ca9

Contents?: true

Size: 1.19 KB

Versions: 109

Compression:

Stored size: 1.19 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` # note: double quotes around path so command also works on Windows

      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

109 entries across 109 versions & 1 rubygems

Version Path
fastlane-2.92.0.beta.20180414050023 frameit/lib/frameit/strings_parser.rb
fastlane-2.91.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.91.0.beta.20180413050017 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180412050111 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180411050056 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180410050128 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180409050033 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180408050113 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180407050037 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180406050006 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180405050125 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180404050031 frameit/lib/frameit/strings_parser.rb
fastlane-2.90.0.beta.20180403050108 frameit/lib/frameit/strings_parser.rb
fastlane-2.89.0 frameit/lib/frameit/strings_parser.rb
fastlane-2.89.0.beta.20180402050042 frameit/lib/frameit/strings_parser.rb
fastlane-2.89.0.beta.20180401050120 frameit/lib/frameit/strings_parser.rb
fastlane-2.89.0.beta.20180331050023 frameit/lib/frameit/strings_parser.rb
fastlane-2.89.0.beta.20180330050046 frameit/lib/frameit/strings_parser.rb
fastlane-2.89.0.beta.20180329050050 frameit/lib/frameit/strings_parser.rb