Sha256: 3845532bb928709aa0ac77142ffea99e27ca15359a1f77fa17138c23a58729e9

Contents?: true

Size: 859 Bytes

Versions: 4

Compression:

Stored size: 859 Bytes

Contents

module Frameit
  # This class will parse the .string files
  class StringsParser
    def self.parse(path)
      raise "Couldn't find strings file at path '#{path}'".red unless File.exist? path
      raise "Must be .strings file, only got '#{path}'".red 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 do |line|
        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
          Helper.log.error ex
          Helper.log.error line
        end
      end

      result
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
frameit-2.4.1 lib/frameit/strings_parser.rb
frameit-2.4.0 lib/frameit/strings_parser.rb
frameit-2.3.0 lib/frameit/strings_parser.rb
frameit-2.2.2 lib/frameit/strings_parser.rb