Commit e87d0f7b89c51700e43994f6f26def06f8cde901
1 parent
85411b0c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Adding script updatepo to support translation
Showing
2 changed files
with
77 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +msgid "Relevant content"# msgstr "Conteúdo relevante" | ... | ... |
| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | +#!/usr/bin/env ruby | |
| 2 | +require File.dirname(__FILE__) + '/../../config/environment' | |
| 3 | + | |
| 4 | +orig_po_filepath = File.join(Rails.root,'po', 'pt', 'noosfero.po') | |
| 5 | +pt_file = File.open(orig_po_filepath) | |
| 6 | + | |
| 7 | +tmp_dir = File.join(File.dirname(__FILE__),'tmp') | |
| 8 | +FileUtils.mkdir_p(tmp_dir) | |
| 9 | +tmp_filepath = File.join(tmp_dir,'noosfero.po') | |
| 10 | +new_pt_file = File.open(tmp_filepath, 'w+') | |
| 11 | +translations_path = File.join(File.dirname(__FILE__),'data', 'pt.upo') | |
| 12 | +translations = {} | |
| 13 | +File.open(translations_path, 'r').readlines.map do |l| | |
| 14 | + a = l.scan(/(.*)# (.*)/).first | |
| 15 | + translations[a[0]] = a[1] | |
| 16 | +end | |
| 17 | + | |
| 18 | +fuzzy = '' | |
| 19 | +header = '' | |
| 20 | +msgid = '' | |
| 21 | +msgstr = '' | |
| 22 | +count = 0 | |
| 23 | +total = '' | |
| 24 | +loading_msgid = false | |
| 25 | +loading_msgstr = false | |
| 26 | +has_new_translation = false | |
| 27 | +pt_file.readlines.map do |line| | |
| 28 | + puts line | |
| 29 | + if line.match('msgid') | |
| 30 | + loading_msgid = true | |
| 31 | + loading_msgstr = false | |
| 32 | + elsif line.match('msgstr') | |
| 33 | + loading_msgid = false | |
| 34 | + loading_msgstr = true | |
| 35 | + end | |
| 36 | + if loading_msgid && line != "\n" | |
| 37 | + loading_msgid = true | |
| 38 | + loading_msgstr = false | |
| 39 | + msgid += line | |
| 40 | + unless translations[line.chomp].nil? | |
| 41 | + has_new_translation = true | |
| 42 | + if !translations[line.chomp].match('msgstr') && !msgstr.match('msgstr') | |
| 43 | + msgstr += "msgstr \"\"\n" | |
| 44 | + end | |
| 45 | + msgstr += translations[line.chomp] + "\n" | |
| 46 | + fuzzy = '' | |
| 47 | + end | |
| 48 | + elsif loading_msgstr && line != "\n" | |
| 49 | + loading_msgid = false | |
| 50 | + loading_msgstr = true | |
| 51 | + next if has_new_translation | |
| 52 | + msgstr += line | |
| 53 | + elsif line.match('fuzzy') | |
| 54 | + fuzzy = line | |
| 55 | + elsif line == "\n" | |
| 56 | + loading_msgid = false | |
| 57 | + loading_msgstr = false | |
| 58 | + has_new_translation = false | |
| 59 | + new_pt_file.write(header) | |
| 60 | + new_pt_file.write(fuzzy) | |
| 61 | + new_pt_file.write(msgid) | |
| 62 | + new_pt_file.write(msgstr) | |
| 63 | + new_pt_file.write("\n") | |
| 64 | + header = '' | |
| 65 | + fuzzy = '' | |
| 66 | + msgid = '' | |
| 67 | + msgstr = '' | |
| 68 | + else | |
| 69 | + header += line | |
| 70 | + end | |
| 71 | +end | |
| 72 | + | |
| 73 | +pt_file.close | |
| 74 | +new_pt_file.close | |
| 75 | + | |
| 76 | +FileUtils.mv(tmp_filepath, orig_po_filepath) | ... | ... |