Class: Applocale::ParseXMLFile
- Inherits:
-
Object
- Object
- Applocale::ParseXMLFile
- Defined in:
- lib/applocale/Core/ParserStringFile/parse_xml_file.rb
Instance Attribute Summary collapse
-
#errorlist ⇒ Object
readonly
Returns the value of attribute errorlist.
-
#in_multiline_comments ⇒ Object
readonly
Returns the value of attribute in_multiline_comments.
-
#injectobj ⇒ Object
readonly
Returns the value of attribute injectobj.
-
#keys_list ⇒ Object
readonly
Returns the value of attribute keys_list.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#strings_keys ⇒ Object
readonly
Returns the value of attribute strings_keys.
Instance Method Summary collapse
-
#initialize(platform, langpathobj_list, injectobj) ⇒ ParseXMLFile
constructor
A new instance of ParseXMLFile.
- #remove_escape(lang, key, content) ⇒ Object
- #to_parse_files(langpathobj_list) ⇒ Object
- #to_parse_strings_file(lang, strings_path) ⇒ Object
Constructor Details
#initialize(platform, langpathobj_list, injectobj) ⇒ ParseXMLFile
Returns a new instance of ParseXMLFile.
10 11 12 13 14 15 16 17 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 10 def initialize(platform, langpathobj_list, injectobj) @strings_keys = {} @keys_list = Array.new @errorlist = Array.new() @platform = platform @injectobj = injectobj self.to_parse_files(langpathobj_list) end |
Instance Attribute Details
#errorlist ⇒ Object (readonly)
Returns the value of attribute errorlist.
8 9 10 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 8 def errorlist @errorlist end |
#in_multiline_comments ⇒ Object (readonly)
Returns the value of attribute in_multiline_comments.
8 9 10 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 8 def in_multiline_comments @in_multiline_comments end |
#injectobj ⇒ Object (readonly)
Returns the value of attribute injectobj.
8 9 10 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 8 def injectobj @injectobj end |
#keys_list ⇒ Object (readonly)
Returns the value of attribute keys_list.
8 9 10 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 8 def keys_list @keys_list end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
8 9 10 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 8 def platform @platform end |
#strings_keys ⇒ Object (readonly)
Returns the value of attribute strings_keys.
8 9 10 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 8 def strings_keys @strings_keys end |
Instance Method Details
#remove_escape(lang, key, content) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 50 def remove_escape(lang, key, content) value = content if @injectobj.has_before_parse_from_locale value = @injectobj.load_before_parse_from_locale(lang.to_s, key, value) end if @injectobj.has_parse_from_locale value = @injectobj.load_parse_from_locale(lang.to_s, key, value) else value = ContentUtil.remove_escape(@platform, value) end if @injectobj.has_after_parse_from_locale value = @injectobj.load_after_parse_from_locale(lang.to_s, key, value) end return value end |
#to_parse_files(langpathobj_list) ⇒ Object
19 20 21 22 23 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 19 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/applocale/Core/ParserStringFile/parse_xml_file.rb', line 25 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 |