aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/develop/po4a.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/develop/po4a.rb')
-rw-r--r--lib/sisu/develop/po4a.rb712
1 files changed, 330 insertions, 382 deletions
diff --git a/lib/sisu/develop/po4a.rb b/lib/sisu/develop/po4a.rb
index 4b41f1da..5cc36886 100644
--- a/lib/sisu/develop/po4a.rb
+++ b/lib/sisu/develop/po4a.rb
@@ -62,7 +62,9 @@ module SiSU_Po4a
require_relative 'shared_metadata' # shared_metadata.rb
require_relative 'po4a_set' # po4a_set.rb
include SiSU_Param
+ require_relative 'object_munge' # object_munge.rb
class Source
+ include SiSU_Object_Munge
@@opt_src,@@opt_trn,@@opt_src_,@@opt_trn_,@@md_src,@@md_trn=
nil, nil, nil, nil, nil, nil
@@auto_translation_ = :go
@@ -210,7 +212,9 @@ module SiSU_Po4a
? md_src
: md_trn
@tab="\t"
- @@endnotes_=(@md.opt.selections.str =~/--endnote/) ? true : false # --footnote
+ @@endnotes_=(@md.opt.selections.str =~/--endnote/) \
+ ? true
+ : false # --footnote
@pot={
body: [],
open: [],
@@ -224,24 +228,20 @@ module SiSU_Po4a
(@md.opt.selections.str =~/--dos/) ? "\r\n" : "\n" # --unix
end
def songsheet
-############## BUG @fn changes value
fn=@fn
pot=pot_markup(@data_src,@data_trn)
publish(fn,pot)
end
- def extract_endnotes(dob='') #% used for extraction of endnotes from paragraphs
- notes_a=dob.obj.scan(/#{Mx[:en_a_o]}([\d]+\s+.+?)#{Mx[:en_a_c]}/)
- ##notes_a=dob.obj.scan(/#{Mx[:en_a_o]}([\d*+]+\s+.+?)#{Mx[:en_a_c]}/)
- #notes_b=dob.obj.scan(/#{Mx[:en_b_o]}([\d*+]+\s+.+?)#{Mx[:en_b_c]}/)
- @n=[]
- notes_a.flatten.each do |n| #high cost to deal with <br> appropriately within plaintext, consider
- n=n.dup.to_s
- n=n.gsub(/^([\d]+)\s+/,'^~\1 ').
- gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,
- ' \\\\\\ ')
- @n << n
- end
- notes_a=@n.flatten
+ def pot_structure_wrap(desc,orig,trans,indent=0,hang=0)
+ SiSU_Po4aUtils::Wrap.new(
+ @md,
+ orig,
+ trans,
+ desc,
+ @wrap_width,
+ indent,
+ hang
+ )
end
def wrap_endnotes(orig_notes='',trn_notes='')
nt=@@endnotes_ ? 'endnote' : 'footnote'
@@ -273,7 +273,7 @@ module SiSU_Po4a
: trn_notes[i].to_s
else ''
end
- util=pot_structure(desc,orig,trans)
+ util=pot_structure_wrap(desc,orig,trans)
wrap=util.line_wrap
wrap=if wrap =~ /^\s*\^~[\d*+]+\s+.+?\s*\Z/m
wrap.gsub(/^\s*(\^~[\d*+]+)\s+(.+?)\s*\Z/m, <<GSUB
@@ -548,29 +548,31 @@ GSUB
#puts z unless z.empty?
end
end
- def pot_structure(desc,orig,trans,indent=0,hang=0)
- SiSU_Po4aUtils::Wrap.new(
- @md,
- orig,
- trans,
- desc,
- @wrap_width,
- indent,
- hang
- )
- end
- def auto_translate?(set=nil)
- @@auto_translation_=set \
- ? set
- : @@auto_translation_
+ def auto_translate?(set_to=nil)
+ @@auto_translation_=
+ if @md.opt.act[:po4a_lang_trans][:set]==:on
+ set_to \
+ ? set_to
+ : @@auto_translation_
+ else :skip
+ end
end
- def auto_translation(src_txt) # check for an appropriate request flag
+ def auto_translation(src_txt,markup=:src) # check for an appropriate request flag
+ auto_translate?(:skip)
begin
+ src_txt_clean=clean_text(src_txt,markup)
+ src_txt_clean=src_txt_clean.
+ gsub(/\n/,' ').
+ gsub(/"/,'\"').
+ gsub(/([()])/,'\\\\\1')
trans=''
unless auto_translate? == :skip
require 'timeout'
- Timeout::timeout(5) {
- #trans=`trans en:#{@md.opt.f_pth[:lng]} #{src_txt}` #+ ' ,{[G.Tr]},'
+ Timeout::timeout(60) {
+ trans=`trans -b -no-ansi en:#{@md.opt.f_pth[:lng_is]} #{src_txt_clean}`.strip
+ unless trans.empty?
+ trans + ' {[G.Tr]}http://translate.google.com'
+ end
}
end
trans
@@ -579,91 +581,21 @@ GSUB
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
- n=lv - 1
- n3=lv + 2
- util=nil
- fn=(dob_src.name=~/[a-z\d]/i) ? dob_src.name : ''
- mark="#{dob_src.lv}~#{fn} "
- d="#{dob_src.is.to_s} (level #{dob_src.lv})"
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# markup for headings is marker at the start of the line/object, } \
- + %{indicating the heading level, and if provided an associated name tag, } \
- + %{this heading is "#{mark}"}
- s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
- end
- desc="#{d}#{s_mark}#{instruct}"
- orig="#{s_mark}#{dob_src.obj}"
- trans=((dob_trn=='') \
- || (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
- if @@endnotes[:para] \
- and notes_s.length > 0 \
- and not @@endnotes_
- @pot[:body] << br
- wrap_endnotes(notes_s,notes_t)
- elsif @@endnotes[:para] \
- and @@endnotes_
- @pot[:body] << br*2
- end
- end
- def pot_structure_para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
- util=nil
- wrapped=if dob_src.indent =~/[1-9]/ \
- and dob_src.indent == dob_src.hang
- s_mark=desc=orig=trans=''
- if dob_src.bullet_
- mark="_#{dob_src.indent}* "
- d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet"
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \
- + %{an underscore followed by the indent level and an asterisk "#{mark}"}
- s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
- end
- desc="#{d}#{s_mark}#{instruct}"
- else
- mark="_#{dob_src.indent} "
- d="#{dob_src.is.to_s}: indent #{dob_src.indent}"
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# markup for indented text is at the start of the line/object, } \
- + %{an underscore followed by the indent level "#{mark}"}
- s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
- end
- desc="#{d}#{s_mark}#{instruct}"
- end
- orig="#{s_mark}#{dob_src.obj}"
- trans=((dob_trn=='') \
- || (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
- s_mark=desc=orig=trans=''
- mark="_#{dob_src.hang}_#{dob_src.indent} "
- d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}"
+ def pot_structure
+ def 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
+ n=lv - 1
+ n3=lv + 2
+ util=nil
+ fn=(dob_src.name=~/[a-z\d]/i) ? dob_src.name : ''
+ mark="#{dob_src.lv}~#{fn} "
+ d="#{dob_src.is.to_s} (level #{dob_src.lv})"
instruct=s_mark=''
if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# markup for indented text with a first line indented } \
- + %{to a different level from the rest of the paragraph, } \
- + %{is at the start of the line/object, } \
- + %{an underscore and the first indent level } \
- + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"}
+ instruct=%{\n# markup for headings is marker at the start of the line/object, } \
+ + %{indicating the heading level, and if provided an associated name tag, } \
+ + %{this heading is "#{mark}"}
s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
end
desc="#{d}#{s_mark}#{instruct}"
@@ -672,185 +604,271 @@ GSUB
|| (dob_src.obj == dob_trn.obj)) \
? ''
: "#{s_mark}#{dob_trn.obj}"
- if trans.empty? # and --auto-trans
- trans=auto_translation(dob_src.obj)
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
end
- util=pot_structure(desc,orig,trans)
- else
- s_mark=desc=orig=trans=''
- if dob_src.bullet_
- mark='_* '
- d="#{dob_src.is.to_s}: bullet"
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# markup for indented text is at the start of the line/object, } \
- + %{an underscore followed by an asterisk "#{mark}"}
- s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
+ util=pot_structure_wrap(desc,orig,trans)
+ wrapped=util.line_wrap
+ @pot[:body] << wrapped << br # main text, contents, body KEEP
+ if @@endnotes[:para] \
+ and notes_s.length > 0 \
+ and not @@endnotes_
+ @pot[:body] << br
+ wrap_endnotes(notes_s,notes_t)
+ elsif @@endnotes[:para] \
+ and @@endnotes_
+ @pot[:body] << br*2
+ end
+ end
+ def para(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ util=nil
+ wrapped=if dob_src.indent =~/[1-9]/ \
+ and dob_src.indent == dob_src.hang
+ s_mark=desc=orig=trans=''
+ if dob_src.bullet_
+ mark="_#{dob_src.indent}* "
+ d="#{dob_src.is.to_s}: indent #{dob_src.indent}, bullet"
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# markup for indented bullet text is at the start of the line/object, } \
+ + %{an underscore followed by the indent level and an asterisk "#{mark}"}
+ s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ else
+ mark="_#{dob_src.indent} "
+ d="#{dob_src.is.to_s}: indent #{dob_src.indent}"
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# markup for indented text is at the start of the line/object, } \
+ + %{an underscore followed by the indent level "#{mark}"}
+ s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
end
- desc="#{d}#{s_mark}#{instruct}"
orig="#{s_mark}#{dob_src.obj}"
trans=((dob_trn=='') \
|| (dob_src.obj == dob_trn.obj)) \
? ''
: "#{s_mark}#{dob_trn.obj}"
- if trans.empty? # and --auto-trans
- trans=auto_translation(dob_src.obj)
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
end
- else
- mark=''
- d=dob_src.is.to_s
- instruct=%{\n# regular paragraph, no special markup}
+ util=pot_structure_wrap(desc,orig,trans)
+ elsif dob_src.hang =~/[0-9]/ \
+ and dob_src.indent != dob_src.hang
+ s_mark=desc=orig=trans=''
+ mark="_#{dob_src.hang}_#{dob_src.indent} "
+ d="#{dob_src.is.to_s}: hang #{dob_src.hang} indent #{dob_src.indent}"
+ instruct=s_mark=''
if @md.opt.act[:maintenance][:set]==:on
- instruct="\n# "
+ instruct=%{\n# markup for indented text with a first line indented } \
+ + %{to a different level from the rest of the paragraph, } \
+ + %{is at the start of the line/object, } \
+ + %{an underscore and the first indent level } \
+ + %{a second underscore and the indent level for the rest of the paragraph, "#{mark1}"}
s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
end
desc="#{d}#{s_mark}#{instruct}"
- orig=dob_src.obj
+ orig="#{s_mark}#{dob_src.obj}"
trans=((dob_trn=='') \
|| (dob_src.obj == dob_trn.obj)) \
? ''
: "#{s_mark}#{dob_trn.obj}"
- if trans.empty? # and --auto-trans
- trans=auto_translation(dob_src.obj)
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
end
+ util=pot_structure_wrap(desc,orig,trans)
+ else
+ s_mark=desc=orig=trans=''
+ if dob_src.bullet_
+ mark='_* '
+ d="#{dob_src.is.to_s}: bullet"
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# markup for indented text is at the start of the line/object, } \
+ + %{an underscore followed by an asterisk "#{mark}"}
+ s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig="#{s_mark}#{dob_src.obj}"
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{s_mark}#{dob_trn.obj}"
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
+ end
+ else
+ mark=''
+ d=dob_src.is.to_s
+ instruct=%{\n# regular paragraph, no special markup}
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct="\n# "
+ s_mark="\n# " + %{"\\n\\n#{mark}...\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=dob_src.obj
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{s_mark}#{dob_trn.obj}"
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
+ end
+ end
+ util=pot_structure_wrap(desc,orig,trans)
+ end
+ wrapped=util.line_wrap
+ @pot[:body] << wrapped << br # main text, contents, body KEEP
+ if @@endnotes[:para] \
+ and notes_s.length > 0 \
+ and not @@endnotes_
+ @pot[:body] << br
+ wrap_endnotes(notes_s,notes_t)
+ elsif @@endnotes[:para] \
+ and @@endnotes_
+ @pot[:body] << br*2
end
- util=pot_structure(desc,orig,trans)
- end
- wrapped=util.line_wrap
- @pot[:body] << wrapped << br # main text, contents, body KEEP
- if @@endnotes[:para] \
- and notes_s.length > 0 \
- and not @@endnotes_
- @pot[:body] << br
- wrap_endnotes(notes_s,notes_t)
- elsif @@endnotes[:para] \
- and @@endnotes_
- @pot[:body] << br*2
- end
- end
- def pot_structure_block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
- mark="block{\\n\\n...\\n\\n}block"
- d=dob_src.is.to_s
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# block text is a text block with an opening and closing marker, } \
- + %{the content of which may be wrapped}
- s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
- end
- desc="#{d}#{s_mark}#{instruct}"
- orig=dob_src.obj
- trans=((dob_trn=='') \
- || (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
- end
- def pot_structure_group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
- mark="group{\\n\\n...\\n\\n}group"
- d=dob_src.is.to_s
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# group text is a text block with an opening and closing marker, } \
- + %{the content of which may be wrapped}
- s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ def block(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ mark="block{\\n\\n...\\n\\n}block"
+ d=dob_src.is.to_s
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# block text is a text block with an opening and closing marker, } \
+ + %{the content of which may be wrapped}
+ s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=dob_src.obj
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{s_mark}#{dob_trn.obj}"
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
+ end
+ util=pot_structure_wrap(desc,orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
end
- desc="#{d}#{s_mark}#{instruct}"
- orig=dob_src.obj
- trans=((dob_trn=='') \
- || (dob_src.obj == dob_trn.obj)) \
- ? ''
- : "#{s_mark}#{dob_trn.obj}"
- if trans.empty? # and --auto-trans
- trans=auto_translation(dob_src.obj)
+ def group(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ mark="group{\\n\\n...\\n\\n}group"
+ d=dob_src.is.to_s
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# group text is a text block with an opening and closing marker, } \
+ + %{the content of which may be wrapped}
+ s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=dob_src.obj
+ trans=((dob_trn=='') \
+ || (dob_src.obj == dob_trn.obj)) \
+ ? ''
+ : "#{s_mark}#{dob_trn.obj}"
+ if @md.opt.f_pth[:lng_is] !=@md.opt.lng_base \
+ and trans.empty? \
+ and auto_translate?
+ trans=auto_translation(dob_src.obj,:src)
+ end
+ util=pot_structure_wrap(desc,orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
end
- util=pot_structure(desc,orig,trans)
- unwrapped=util.no_line_wrap_block
- @pot[:body] << unwrapped << br
- end
- def pot_structure_verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
- mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem"
- d=dob_src.is.to_s
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# verse are part of the text block described as a poem, } \
- + %{the first verse is preceeded by an opening marker, } \
- + %{and the last verse by a closing marker, } \
- + %{the content of which should remain unwrapped}
- s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ def verse(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ mark="poem{\n\nverse\n\nverse\n\n...\n\n}poem"
+ d=dob_src.is.to_s
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# verse are part of the text block described as a poem, } \
+ + %{the first verse is preceeded by an opening marker, } \
+ + %{and the last verse by a closing marker, } \
+ + %{the content of which should remain unwrapped}
+ s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=dob_src.obj
+ trans=(dob_trn=='') ? '' : dob_trn.obj
+ util=pot_structure_wrap(desc,orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
end
- desc="#{d}#{s_mark}#{instruct}"
- orig=dob_src.obj
- trans=(dob_trn=='') ? '' : dob_trn.obj
- util=pot_structure(desc,orig,trans)
- unwrapped=util.no_line_wrap_block
- @pot[:body] << unwrapped << br
- end
- def pot_structure_code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
- mark="code{\\n\\n...\\n\\n}code"
- d=dob_src.is.to_s
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \
- + %{the content of which should remain unwrapped}
- s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ def code(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ mark="code{\\n\\n...\\n\\n}code"
+ d=dob_src.is.to_s
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# codeblocks are a text block with an opening and closing marker, } \
+ + %{the content of which should remain unwrapped}
+ s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=dob_src.obj
+ trans=(dob_trn=='') ? '' : dob_trn.obj
+ util=pot_structure_wrap(desc,orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
end
- desc="#{d}#{s_mark}#{instruct}"
- orig=dob_src.obj
- trans=(dob_trn=='') ? '' : dob_trn.obj
- util=pot_structure(desc,orig,trans)
- unwrapped=util.no_line_wrap_block
- @pot[:body] << unwrapped << br
- end
- def pot_structure_table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
- mark="table{\\n\\n...\\n\\n}table"
- d=dob_src.is.to_s
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# tables are a text block with an opening and closing marker, } \
- + %{the content of which should remain unwrapped}
- s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ def table(dob_src='',notes_s='',dob_trn='',notes_t='') #% used to extract the structure of a document
+ mark="table{\\n\\n...\\n\\n}table"
+ d=dob_src.is.to_s
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# tables are a text block with an opening and closing marker, } \
+ + %{the content of which should remain unwrapped}
+ s_mark="\n# " + %{"\\n\\n#{mark}\\n\\n"}
+ end
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=dob_src.obj
+ orig=orig.gsub(/#{Mx[:tc_c]}/,"\n")
+ trans=(dob_trn=='') ? '' : dob_trn.obj
+ trans=trans.gsub(/#{Mx[:tc_c]}/,"\n")
+ util=pot_structure_wrap(desc,orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
end
- desc="#{d}#{s_mark}#{instruct}"
- orig=dob_src.obj
- orig=orig.gsub(/#{Mx[:tc_c]}/,"\n")
- trans=(dob_trn=='') ? '' : dob_trn.obj
- trans=trans.gsub(/#{Mx[:tc_c]}/,"\n")
- util=pot_structure(desc,orig,trans)
- unwrapped=util.no_line_wrap_block
- @pot[:body] << unwrapped << br
- end
- def pot_structure_idx_markup(idx)
- struct=['={']
- idx.sort.each do |x|
- x.each_with_index do |y,i0|
- case y
- when String
- struct << ';' unless struct[-1] =~/=\{/
- struct << y
- if x[i0+1].class == Hash \
- and x[i0+1][:sub].length > 0
- struct << ':'
- end
- when Hash
- if y[:plus].to_i > 0
- struct << '+' + y[:plus].to_s
- end
- if y[:sub].length > 0
- y[:sub].each_with_index do |z,i1|
- z.each_with_index do |a,i2|
- #p a
- if z.length > 0
- struct << a[0]
- if a[1][:plus].to_i > 0
- struct << '+' + a[1][:plus].to_s
- end
- if (i1 + 1) < y[:sub].length
- struct << '|'
+ def idx_markup(idx)
+ struct=['={']
+ idx.sort.each do |x|
+ x.each_with_index do |y,i0|
+ case y
+ when String
+ struct << ';' unless struct[-1] =~/=\{/
+ struct << y
+ if x[i0+1].class == Hash \
+ and x[i0+1][:sub].length > 0
+ struct << ':'
+ end
+ when Hash
+ if y[:plus].to_i > 0
+ struct << '+' + y[:plus].to_s
+ end
+ if y[:sub].length > 0
+ y[:sub].each_with_index do |z,i1|
+ z.each_with_index do |a,i2|
+ #p a
+ if z.length > 0
+ struct << a[0]
+ if a[1][:plus].to_i > 0
+ struct << '+' + a[1][:plus].to_s
+ end
+ if (i1 + 1) < y[:sub].length
+ struct << '|'
+ end
end
end
end
@@ -858,31 +876,32 @@ GSUB
end
end
end
+ struct << '}'
+ #puts struct.join
+ struct.join
end
- struct << '}'
- #puts struct.join
- struct.join
- end
- def pot_structure_idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix
- mark="={ ... }"
- instruct=s_mark=''
- if @md.opt.act[:maintenance][:set]==:on
- instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
- + %{(there should be a new line, but no empty line)}
- s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
- end
- d='book-idx'
- desc="#{d}#{s_mark}#{instruct}"
- orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
- trans=if defined? dob_trn.idx \
- and not dob_trn.idx.nil? \
- and not dob_trn.idx.empty?
- pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
- else ''
+ def idx(dob_src='',dob_trn='') #% used for book index but broken as original markup lost, already abstracted, fix
+ mark="={ ... }"
+ instruct=s_mark=''
+ if @md.opt.act[:maintenance][:set]==:on
+ instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
+ + %{(there should be a new line, but no empty line)}
+ s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
+ end
+ d='book-idx'
+ desc="#{d}#{s_mark}#{instruct}"
+ orig=pot_structure.idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
+ trans=if defined? dob_trn.idx \
+ and not dob_trn.idx.nil? \
+ and not dob_trn.idx.empty?
+ pot_structure.idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
+ else ''
+ end
+ util=pot_structure_wrap(desc,orig,trans)
+ unwrapped=util.no_line_wrap_block
+ @pot[:body] << unwrapped << br
end
- util=pot_structure(desc,orig,trans)
- unwrapped=util.no_line_wrap_block
- @pot[:body] << unwrapped << br
+ self
end
def pot_markup(data_src,data_trn)
#@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
@@ -1003,24 +1022,24 @@ GSUB
end
case dob_src.is
when :heading
- pot_structure_heading(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.heading(dob_src,notes_s,dob_trn,notes_t)
when :para
- pot_structure_para(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.para(dob_src,notes_s,dob_trn,notes_t)
when :group
- pot_structure_group(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.group(dob_src,notes_s,dob_trn,notes_t)
when :block
- pot_structure_block(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.block(dob_src,notes_s,dob_trn,notes_t)
when :verse
- pot_structure_verse(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.verse(dob_src,notes_s,dob_trn,notes_t)
when :code
- pot_structure_code(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.code(dob_src,notes_s,dob_trn,notes_t)
when :table
- pot_structure_table(dob_src,notes_s,dob_trn,notes_t)
+ pot_structure.table(dob_src,notes_s,dob_trn,notes_t)
end
if defined? dob_src.idx \
and not dob_src.idx.nil? \
and not dob_src.idx.empty?
- pot_structure_idx(dob_src,dob_trn)
+ pot_structure.idx(dob_src,dob_trn)
end
dob_src='' if (dob_src.obj =~/<a name="n\d+">/ \
and dob_src.obj =~/^(-\{{2}~\d+|<!e[:_]\d+!>)/) # -endnote
@@ -1031,83 +1050,8 @@ GSUB
end
#[dob_src,dob_trn]
end
- def markup(dob) # used for major markup instructions
- SiSU_Env::InfoEnv.new(@md.fns)
- dob.obj=dob.obj.
- gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,
- "#{Px[:po_bold_o]}\\1#{Px[:po_bold_c]}").
- gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,
- "#{Px[:po_italics_o]}\\1#{Px[:po_italics_c]}").
- gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,
- "#{Px[:po_underscore_o]}\\1#{Px[:po_underscore_c]}").
- gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,
- "#{Px[:po_subscript_o]}\\1#{Px[:po_subscript_c]}").
- gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,
- "#{Px[:po_superscript_o]}\\1#{Px[:po_superscript_c]}").
- gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,
- "#{Px[:po_insert_o]}\\1#{Px[:po_insert_c]}").
- gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,
- "#{Px[:po_cite_o]}\\1#{Px[:po_cite_c]}").
- gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,
- "#{Px[:po_strike_o]}\\1#{Px[:po_strike_c]}").
- gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,
- "#{Px[:po_monospace_o]}\\1#{Px[:po_monospace_c]}")
- notes=''
- unless dob.is==:code
- dob.obj=dob.obj.
- gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1').
- gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
- gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
- '\1 [link: <\2>]').
- gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,
- '\1 [link: local image]').
- gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1')
- notes=extract_endnotes(dob)
- #% ### footnotes current state - extracted
- dob.obj=dob.obj.
- gsub(/#{Mx[:en_a_o]}([\d]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'~^'). # endnote marker marked up
- #% ### footnotes current state - keep inline
- #dob.obj.gsub!(/#{Mx[:en_a_o]}[\d]+\s+(.+?)#{Mx[:en_a_c]}/,'~{ \1 }~') # inline endnote with marker marked up
- gsub(/#{Mx[:en_b_o]}[\d]+\s+(.+?)#{Mx[:en_b_c]}/,
- '~[ \1 ]~'). # inline endnote with marker marked up
- gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/,
- '~{\1 \2 }~'). # inline endnote with marker marked up
- gsub(/#{Mx[:en_b_o]}([*+]+)\s+(.+?)#{Mx[:en_b_c]}/,
- '~[\1 \2 ]~'). # inline endnote with marker marked up
- gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<').
- gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>').
- gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&').
- gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!').
- gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#').
- gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*').
- gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-').
- gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/').
- gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_').
- gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{').
- gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}').
- gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~').
- gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©')
- end
- dob.obj=if dob.of==:block # watch
- dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/,"* ").
- gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n")
- else dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,"\n\n")
- end
- if dob.is==:code
- dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _<
- gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_<
- end
- dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}/,''). # remove page breaks
- gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1').
- gsub(/<a href=".+?">(.+?)<\/a>/m,'\1').
- gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links
- gsub(/&nbsp;|#{Mx[:nbsp]}/,' '). # decide on
- gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,
- ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
- gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,
- ' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]")
- gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,
- '[image: "\1"]')
+ def markup(dob)
+ dob,notes=objects.textface_marks_po4a(dob,:separate)
[dob,notes]
end
def publish(fn,pot)
@@ -1129,7 +1073,7 @@ GSUB
@file=SiSU_Env::FileOp.new(md,fn)
end
def po4a #%pot output
- file_pot=(@md.opt.f_pth[:lng] ==@md.opt.lng_base) \
+ file_pot=(@md.opt.f_pth[:lng] == @md.opt.lng_base) \
? @file.write_file.pot
: @file.write_file.po
@sisu=[]
@@ -1162,7 +1106,7 @@ GSUB
unless FileTest.directory?(@file.output_path.pot_git.dir)
git.create_file_structure_git
end
- if @md.opt.f_pth[:lng] ==@md.opt.lng_base
+ if @md.opt.f_pth[:lng] == @md.opt.lng_base
FileUtils::cp(
@file.place_file.pot.dir,
@file.output_path.pot_git.dir
@@ -1193,3 +1137,7 @@ where no ocn appropriately use ~# or -# or indeed 1~name-
comments in document, what to do about them, not sure they are currently
retained in dal, could be quite valuable to keep
+
+Translate Shell
+http://www.soimort.org/translate-shell/
+translate.google.com