Class: PoAndXliffConsolidator::Combine
- Inherits:
-
Object
- Object
- PoAndXliffConsolidator::Combine
- Includes:
- Logging, FileHandle, Manipulate
- Defined in:
- lib/po_and_xliff_consolidator/combine.rb
Instance Attribute Summary
Attributes included from FileHandle
#app_name, #path_templates, #root_file_path
Attributes included from Manipulate
#reset_identical_msgid_and_msgstr, #skip_regexes, #skip_strings
Instance Method Summary collapse
- #process(language_code) ⇒ Object
- #process_web_app ⇒ Object
- #process_xliff ⇒ Object
- #write_output_file ⇒ Object
Methods included from Logging
included, logger, #logger, logger=
Methods included from FileHandle
#combined_file_name, #get_path, #initialize, #web_app_file_pointer, #web_app_filename, #xcode_doc, #xcode_file_name
Methods included from Manipulate
#add_translation_unit, #initialize, #reset_stores, #set_language_codes, #should_skip?
Instance Method Details
#process(language_code) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/po_and_xliff_consolidator/combine.rb', line 16 def process(language_code) set_language_codes(language_code) reset_stores process_web_app process_xliff write_output_file logger.info "#{@translation_units.count} translation units" logger.info "#{@untranslated_count} untranslated phrases" logger.info "#{@untranslated_word_count} untranslated words" logger.info "#{@duplicate_count} duplicates" end |
#process_web_app ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/po_and_xliff_consolidator/combine.rb', line 60 def process_web_app fp = web_app_file_pointer(:need_translating,'r') while(line = fp.gets) @headers << line break if line.strip == '' end while(line = fp.gets) if match1 = @msgid_regex.match(line) msgid = match1[1] if line = fp.gets if match2 = @msgstr_regex.match(line) msgstr = match2[1] add_translation_unit(msgid, msgstr) elsif match2 = @msgid_plural_regex.match(line) block = [match1[0], match2[0]] line = fp.gets while line.strip != '' block << line line = fp.gets end @unsolved_blocks << block else throw "I don't know what to do.." end end end end fp.close end |
#process_xliff ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/po_and_xliff_consolidator/combine.rb', line 95 def process_xliff xcode_doc(:need_translating).xpath('//xmlns:file').each do |xcode_file_node| xcode_file_node.xpath('xmlns:body/xmlns:trans-unit').each do |xcode_trans_unit_node| xcode_source = xcode_trans_unit_node.xpath('xmlns:source').last xcode_targets = xcode_trans_unit_node.xpath('xmlns:target') msgid = xcode_source.text msgstr = '' xtc = xcode_targets.count if xtc == 1 msgstr = xcode_targets.first.text elsif xtc > 1 throw "I don't know what to do.." end add_translation_unit(msgid, msgstr) end end end |
#write_output_file ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/po_and_xliff_consolidator/combine.rb', line 28 def write_output_file fp = File.open(combined_file_name,'w') comments_need_adding = true @headers.each do |header| if comments_need_adding && header =~ /^msgid\s""$/ fp.puts "# #{@translation_units.count} translation units (phrases)" fp.puts "# #{@untranslated_count} untranslated phrases" fp.puts "# #{@untranslated_word_count} untranslated words" fp.puts "# #{@duplicate_count} duplicates" fp.puts '#' comments_need_adding = false end fp.puts header end @translation_units.sort! @translation_units.each do |tu| fp.puts "msgid \"#{tu.msgid}\"" fp.puts "msgstr \"#{tu.msgstr}\"" fp.puts end @unsolved_blocks.each do |ub| ub.each do |ube| fp.puts ube end fp.puts end fp.close end |