Class: Applocale::ParseXMLFile

Inherits:
Object
  • Object
show all
Defined in:
lib/applocale/Core/ParserStringFile/parse_xml_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, langpathobj_list, convert_file) ⇒ ParseXMLFile

Returns a new instance of ParseXMLFile.



12
13
14
15
16
17
18
19
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 12

def initialize(platform, langpathobj_list, convert_file)
  @strings_keys = {}
  @keys_list = Array.new
  @errorlist = Array.new()
  @platform = platform
  @convert_file = convert_file
  self.to_parse_files(langpathobj_list)
end

Instance Attribute Details

#convert_fileObject (readonly)

Returns the value of attribute convert_file.



9
10
11
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 9

def convert_file
  @convert_file
end

#errorlistObject (readonly)

Returns the value of attribute errorlist.



9
10
11
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 9

def errorlist
  @errorlist
end

#in_multiline_commentsObject (readonly)

Returns the value of attribute in_multiline_comments.



9
10
11
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 9

def in_multiline_comments
  @in_multiline_comments
end

#keys_listObject (readonly)

Returns the value of attribute keys_list.



9
10
11
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 9

def keys_list
  @keys_list
end

#platformObject (readonly)

Returns the value of attribute platform.



9
10
11
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 9

def platform
  @platform
end

#strings_keysObject (readonly)

Returns the value of attribute strings_keys.



9
10
11
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 9

def strings_keys
  @strings_keys
end

Instance Method Details

#remove_escape(lang, key, content) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 52

def remove_escape(lang, key, content)
  value = ContentUtil.remove_escape(@platform, content)
  if @convert_file.has_parse_from_locale
    return @convert_file.load_parse_from_locale(lang.to_s, key,  content, value)
  end
  return value
end

#to_parse_files(langpathobj_list) ⇒ Object



21
22
23
24
25
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 21

def to_parse_files(langpathobj_list)
  langpathobj_list.each do |langpathobj|
    self.to_parse_strings_file(langpathobj.lang, langpathobj.filepath)
  end
end

#to_parse_strings_file(lang, strings_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 27

def to_parse_strings_file(lang, strings_path)
  return if !File.exist? strings_path
  puts "Start to Parse xml file: \"#{strings_path}\" ...".green

  xml_doc = Nokogiri::XML(File.open(strings_path))
  string_nodes = xml_doc.xpath("//string")
  string_nodes.each do |node|
    key = node["name"]
    value = node.content
    if !key.nil? && key.strip.length > 0
      if @strings_keys[key].nil?
        @strings_keys[key] = Hash.new
        @keys_list.push(key)
      end
      if @strings_keys[key][lang.to_s].nil?
        @strings_keys[key][lang.to_s] = Hash.new
        @strings_keys[key][lang.to_s][:value] = self.remove_escape(lang, key, value)
      else
        error = ErrorUtil::ParseLocalizedError::DuplicateKey.new(key, -1, strings_path, lang, -1)
        @errorlist.push(error)
      end
    end
  end
end