From 311c40ace0cf921b0c3ba200f9d17de25a4e65b8 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 26 Dec 2014 21:51:11 -0500 Subject: d: po4a, stub for auto-translate * intention (stub only, not implemented) * '--po4a --trans --glob test.sst' run against en/test.sst fr/test.sst * '--po4a --trans-en:fr en/test.sst' to send identical text objects to translate.google using 'trans' and populate po file with results for placing future translation under po4a management --- lib/sisu/develop/po4a.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'lib') diff --git a/lib/sisu/develop/po4a.rb b/lib/sisu/develop/po4a.rb index 1ce46d1b..3a93c7fd 100644 --- a/lib/sisu/develop/po4a.rb +++ b/lib/sisu/develop/po4a.rb @@ -65,6 +65,7 @@ module SiSU_Po4a class Source @@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn= nil,nil,nil,nil,nil,nil + @@auto_translation_ = :go def initialize(opt,fn=nil) @opt,@fn=opt,fn #unless @opt.fns =~/(.+?\.(?:-|ssm\.)?sst)$/ @@ -544,6 +545,26 @@ GSUB hang ) end + def auto_translate?(set=nil) + @@auto_translation_=set \ + ? set + : @@auto_translation_ + end + def auto_translation(src_txt) # check for an appropriate request flag + begin + trans='' + unless auto_translate? == :skip + require 'timeout' + Timeout::timeout(5) { + #trans=`trans en:#{@md.opt.f_pth[:lng]} #{src_txt}` #+ ' ,{[G.Tr]},' + } + end + trans + rescue + auto_translate?(:skip) + p 'timeout issues with translation, skip remaining' + end + end def pot_structure_heading(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document lv=n=n3=nil lv=dob_src.ln @@ -566,6 +587,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end util=pot_structure(desc,orig,trans) wrapped=util.line_wrap @pot[:body] << wrapped << br # main text, contents, body KEEP @@ -610,6 +634,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end util=pot_structure(desc,orig,trans) elsif dob_src.hang =~/[0-9]/ \ and dob_src.indent != dob_src.hang @@ -631,6 +658,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end util=pot_structure(desc,orig,trans) else s_mark=desc=orig=trans='' @@ -649,6 +679,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end else mark='' d=dob_src.is.to_s @@ -663,6 +696,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end end util=pot_structure(desc,orig,trans) end @@ -693,6 +729,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block @pot[:body] << unwrapped << br @@ -712,6 +751,9 @@ GSUB || (dob_src.obj == dob_trn.obj)) \ ? '' : "#{s_mark}#{dob_trn.obj}" + if trans.empty? # and --auto-trans + trans=auto_translation(dob_src.obj) + end util=pot_structure(desc,orig,trans) unwrapped=util.no_line_wrap_block @pot[:body] << unwrapped << br -- cgit v1.2.3