isodoc 1.1.4 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc-yaml/i18n-en.yaml +4 -1
  3. data/lib/isodoc-yaml/i18n-fr.yaml +4 -1
  4. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +4 -1
  5. data/lib/isodoc.rb +1 -0
  6. data/lib/isodoc/common.rb +0 -2
  7. data/lib/isodoc/convert.rb +33 -27
  8. data/lib/isodoc/function/blocks.rb +10 -22
  9. data/lib/isodoc/function/blocks_example_note.rb +14 -15
  10. data/lib/isodoc/function/cleanup.rb +5 -4
  11. data/lib/isodoc/function/inline.rb +6 -76
  12. data/lib/isodoc/function/references.rb +10 -9
  13. data/lib/isodoc/function/reqt.rb +12 -11
  14. data/lib/isodoc/function/section.rb +39 -54
  15. data/lib/isodoc/function/table.rb +1 -6
  16. data/lib/isodoc/function/terms.rb +13 -6
  17. data/lib/isodoc/function/to_word_html.rb +1 -0
  18. data/lib/isodoc/function/utils.rb +4 -3
  19. data/lib/isodoc/html_function/html.rb +0 -1
  20. data/lib/isodoc/{function/i18n.rb → i18n.rb} +37 -36
  21. data/lib/isodoc/metadata.rb +4 -3
  22. data/lib/isodoc/metadata_date.rb +1 -1
  23. data/lib/isodoc/presentation_function/block.rb +138 -0
  24. data/lib/isodoc/presentation_function/inline.rb +131 -0
  25. data/lib/isodoc/presentation_function/section.rb +46 -0
  26. data/lib/isodoc/presentation_xml_convert.rb +38 -5
  27. data/lib/isodoc/version.rb +1 -1
  28. data/lib/isodoc/word_function/body.rb +12 -8
  29. data/lib/isodoc/word_function/inline.rb +3 -1
  30. data/lib/isodoc/xref.rb +5 -3
  31. data/lib/isodoc/xref/xref_sect_gen.rb +3 -3
  32. data/spec/assets/i18n.yaml +12 -1
  33. data/spec/isodoc/blocks_spec.rb +1101 -147
  34. data/spec/isodoc/cleanup_spec.rb +2 -2
  35. data/spec/isodoc/footnotes_spec.rb +2 -2
  36. data/spec/isodoc/i18n_spec.rb +679 -110
  37. data/spec/isodoc/inline_spec.rb +323 -142
  38. data/spec/isodoc/lists_spec.rb +2 -2
  39. data/spec/isodoc/postproc_spec.rb +1311 -1333
  40. data/spec/isodoc/ref_spec.rb +181 -3
  41. data/spec/isodoc/section_spec.rb +508 -680
  42. data/spec/isodoc/table_spec.rb +155 -4
  43. data/spec/isodoc/terms_spec.rb +111 -79
  44. data/spec/isodoc/xref_spec.rb +1569 -1186
  45. metadata +6 -3
@@ -5,7 +5,7 @@ module IsoDoc::Function
5
5
  # references anyway; keeping here instead of in IsoDoc::Iso for now
6
6
  def docid_l10n(x)
7
7
  return x if x.nil?
8
- x.gsub(/All Parts/i, @all_parts_lbl.downcase) if @all_parts_lbl
8
+ x.gsub(/All Parts/i, @i18n.all_parts.downcase) if @i18n.all_parts
9
9
  x
10
10
  end
11
11
 
@@ -155,14 +155,14 @@ module IsoDoc::Function
155
155
 
156
156
  def norm_ref_xpath
157
157
  "//bibliography/references[@normative = 'true'] | "\
158
- "//bibliography/clause[.//references[@normative = 'true']]"
158
+ "//bibliography/clause[.//references[@normative = 'true']]"
159
159
  end
160
160
 
161
161
  def norm_ref(isoxml, out, num)
162
162
  f = isoxml.at(ns(norm_ref_xpath)) or return num
163
163
  out.div do |div|
164
164
  num = num + 1
165
- clause_name(num, @normref_lbl, div, nil)
165
+ clause_name(num, f.at(ns("./title")), div, nil)
166
166
  if f.name == "clause"
167
167
  f.elements.each { |e| parse(e, div) unless e.name == "title" }
168
168
  else
@@ -174,15 +174,18 @@ module IsoDoc::Function
174
174
 
175
175
  def bibliography_xpath
176
176
  "//bibliography/clause[.//references]"\
177
- "[not(.//references[@normative = 'true'])] | "\
178
- "//bibliography/references[@normative = 'false']"
177
+ "[not(.//references[@normative = 'true'])] | "\
178
+ "//bibliography/references[@normative = 'false']"
179
179
  end
180
180
 
181
181
  def bibliography(isoxml, out)
182
182
  f = isoxml.at(ns(bibliography_xpath)) || return
183
183
  page_break(out)
184
184
  out.div do |div|
185
- div.h1 @bibliography_lbl, **{ class: "Section3" }
185
+ #div.h1 @bibliography_lbl, **{ class: "Section3" }
186
+ div.h1 **{class: "Section3"} do |h1|
187
+ f&.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
188
+ end
186
189
  biblio_list(f, div, true)
187
190
  end
188
191
  end
@@ -190,9 +193,7 @@ module IsoDoc::Function
190
193
  def bibliography_parse(node, out)
191
194
  title = node&.at(ns("./title"))&.text || ""
192
195
  out.div do |div|
193
- @xrefs.anchor(node['id'], :label, false) and
194
- clause_parse_title(node, div, node.at(ns("./title")), out) or
195
- div.h2 title, **{ class: "Section3" }
196
+ clause_parse_title(node, div, node.at(ns("./title")), out, { class: "Section3" })
196
197
  biblio_list(node, div, true)
197
198
  end
198
199
  end
@@ -1,14 +1,14 @@
1
1
  module IsoDoc::Function
2
2
  module Blocks
3
3
  def recommendation_labels(node)
4
- [node.at(ns("./label")), node.at(ns("./title")),
5
- @xrefs.anchor(node['id'], :label, false)]
4
+ [node.at(ns("./label")), node.at(ns("./title")), node.at(ns("./name"))]
6
5
  end
7
6
 
8
- def recommendation_name(node, out, type)
7
+ def recommendation_name(node, out, _type)
9
8
  label, title, lbl = recommendation_labels(node)
10
9
  out.p **{ class: "RecommendationTitle" } do |b|
11
- b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:"))
10
+ lbl and lbl.children.each { |n| parse(n, b) }
11
+ b << l10n(":")
12
12
  if label || title
13
13
  b.br
14
14
  label and label.children.each { |n| parse(n,b) }
@@ -21,11 +21,11 @@ module IsoDoc::Function
21
21
  def recommendation_attributes1(node)
22
22
  out = []
23
23
  oblig = node["obligation"] and
24
- out << l10n("#{@labels['obligation']}: #{oblig}")
24
+ out << l10n("#{@i18n.obligation}: #{oblig}")
25
25
  subj = node&.at(ns("./subject"))&.text and
26
- out << l10n("#{@labels['subject']}: #{subj}")
26
+ out << l10n("#{@i18n.subject}: #{subj}")
27
27
  node.xpath(ns("./inherit")).each do |i|
28
- out << recommendation_attr_parse(i, @labels["inherits"])
28
+ out << recommendation_attr_parse(i, @i18n.inherits)
29
29
  end
30
30
  node.xpath(ns("./classification")).each do |c|
31
31
  line = recommendation_attr_keyvalue(c, "tag", "value") and out << line
@@ -57,7 +57,8 @@ module IsoDoc::Function
57
57
  end
58
58
 
59
59
  def reqt_metadata_node(n)
60
- %w(label title subject classification tag value inherit).include? n.name
60
+ %w(label title subject classification tag value
61
+ inherit name).include? n.name
61
62
  end
62
63
 
63
64
  def reqt_attrs(node, klass)
@@ -66,7 +67,7 @@ module IsoDoc::Function
66
67
 
67
68
  def recommendation_parse(node, out)
68
69
  out.div **reqt_attrs(node, "recommend") do |t|
69
- recommendation_name(node, t, @recommendation_lbl)
70
+ recommendation_name(node, t, @i18n.recommendation)
70
71
  recommendation_attributes(node, out)
71
72
  node.children.each do |n|
72
73
  parse(n, t) unless reqt_metadata_node(n)
@@ -76,7 +77,7 @@ module IsoDoc::Function
76
77
 
77
78
  def requirement_parse(node, out)
78
79
  out.div **reqt_attrs(node, "require") do |t|
79
- recommendation_name(node, t, @requirement_lbl)
80
+ recommendation_name(node, t, @i18n.requirement)
80
81
  recommendation_attributes(node, out)
81
82
  node.children.each do |n|
82
83
  parse(n, t) unless reqt_metadata_node(n)
@@ -86,7 +87,7 @@ module IsoDoc::Function
86
87
 
87
88
  def permission_parse(node, out)
88
89
  out.div **reqt_attrs(node, "permission") do |t|
89
- recommendation_name(node, t, @permission_lbl)
90
+ recommendation_name(node, t, @i18n.permission)
90
91
  recommendation_attributes(node, out)
91
92
  node.children.each do |n|
92
93
  parse(n, t) unless reqt_metadata_node(n)
@@ -8,36 +8,37 @@ module IsoDoc::Function
8
8
  insert_tab(out, 1)
9
9
  end
10
10
 
11
- def inline_header_title(out, node, c1)
11
+ def inline_header_title(out, node, title)
12
12
  out.span **{ class: "zzMoveToFollowing" } do |s|
13
13
  s.b do |b|
14
- if @xrefs.anchor(node['id'], :label, false) && !@suppressheadingnumbers
15
- b << "#{@xrefs.anchor(node['id'], :label)}#{clausedelim}"
16
- clausedelimspace(out)
17
- end
18
- c1&.children&.each { |c2| parse(c2, b) }
19
- clausedelimspace(out) if /\S/.match(c1&.text)
14
+ title&.children&.each { |c2| parse(c2, b) }
15
+ clausedelimspace(out) if /\S/.match(title&.text)
20
16
  end
21
17
  end
22
18
  end
23
19
 
24
20
  # used for subclauses
25
- def clause_parse_title(node, div, c1, out)
21
+ def clause_parse_title(node, div, title, out, header_class = {})
22
+ return if title.nil?
26
23
  if node["inline-header"] == "true"
27
- inline_header_title(out, node, c1)
24
+ inline_header_title(out, node, title)
28
25
  else
29
- div.send "h#{@xrefs.anchor(node['id'], :level, false) || '1'}" do |h|
30
- lbl = @xrefs.anchor(node['id'], :label, false)
31
- h << "#{lbl}#{clausedelim}" if lbl && !@suppressheadingnumbers
32
- clausedelimspace(out) if lbl && !@suppressheadingnumbers
33
- c1&.children&.each { |c2| parse(c2, h) }
26
+ depth = (title && title["depth"]) ? title["depth"] :
27
+ node.ancestors("clause, annex, terms, references, definitions, "\
28
+ "acknowledgements, introduction, foreword").size + 1
29
+ div.send "h#{depth}", **attr_code(header_class) do |h|
30
+ title&.children&.each { |c2| parse(c2, h) }
34
31
  end
35
32
  end
36
33
  end
37
34
 
35
+ def clause_attrs(node)
36
+ { id: node["id"] }
37
+ end
38
+
38
39
  # used for subclauses
39
40
  def clause_parse(node, out)
40
- out.div **attr_code(id: node["id"]) do |div|
41
+ out.div **attr_code(clause_attrs(node)) do |div|
41
42
  clause_parse_title(node, div, node.at(ns("./title")), out)
42
43
  node.children.reject { |c1| c1.name == "title" }.each do |c1|
43
44
  parse(c1, div)
@@ -45,13 +46,9 @@ module IsoDoc::Function
45
46
  end
46
47
  end
47
48
 
48
- def clause_name(num, title, div, header_class)
49
+ def clause_name(_num, title, div, header_class)
49
50
  header_class = {} if header_class.nil?
50
51
  div.h1 **attr_code(header_class) do |h1|
51
- if num && !@suppressheadingnumbers
52
- h1 << "#{num}#{clausedelim}"
53
- clausedelimspace(h1)
54
- end
55
52
  title.is_a?(String) ? h1 << title :
56
53
  title&.children&.each { |c2| parse(c2, h1) }
57
54
  end
@@ -60,9 +57,8 @@ module IsoDoc::Function
60
57
 
61
58
  def clause(isoxml, out)
62
59
  isoxml.xpath(ns(middle_clause)).each do |c|
63
- out.div **attr_code(id: c["id"]) do |s|
64
- clause_name(@xrefs.anchor(c['id'], :label),
65
- c&.at(ns("./title")), s, nil)
60
+ out.div **attr_code(clause_attrs(c)) do |s|
61
+ clause_name(nil, c&.at(ns("./title")), s, nil)
66
62
  c.elements.reject { |c1| c1.name == "title" }.each do |c1|
67
63
  parse(c1, s)
68
64
  end
@@ -71,19 +67,20 @@ module IsoDoc::Function
71
67
  end
72
68
 
73
69
  def annex_name(annex, name, div)
70
+ return if name.nil?
74
71
  div.h1 **{ class: "Annex" } do |t|
75
- t << "#{@xrefs.anchor(annex['id'], :label)}<br/><br/>"
76
- t.b do |b|
77
- name&.children&.each { |c2| parse(c2, b) }
78
- end
72
+ name.children.each { |c2| parse(c2, t) }
79
73
  end
80
74
  end
81
75
 
76
+ def annex_attrs(node)
77
+ { id: node["id"], class: "Section3" }
78
+ end
79
+
82
80
  def annex(isoxml, out)
83
81
  isoxml.xpath(ns("//annex")).each do |c|
84
82
  page_break(out)
85
- out.div **attr_code(id: c["id"], class: "Section3") do |s|
86
- annex_name(c, nil, s) unless c.at(ns("./title"))
83
+ out.div **attr_code(annex_attrs(c)) do |s|
87
84
  c.elements.each do |c1|
88
85
  if c1.name == "title" then annex_name(c, c1, s)
89
86
  else
@@ -95,10 +92,10 @@ module IsoDoc::Function
95
92
  end
96
93
 
97
94
  def scope(isoxml, out, num)
98
- f = isoxml.at(ns("//clause[title = 'Scope']")) or return num
95
+ f = isoxml.at(ns("//clause[@type = 'scope']")) or return num
99
96
  out.div **attr_code(id: f["id"]) do |div|
100
97
  num = num + 1
101
- clause_name(num, @scope_lbl, div, nil)
98
+ clause_name(num, f&.at(ns("./title")), div, nil)
102
99
  f.elements.each do |e|
103
100
  parse(e, div) unless e.name == "title"
104
101
  end
@@ -109,26 +106,11 @@ module IsoDoc::Function
109
106
  TERM_CLAUSE = "//sections/terms | "\
110
107
  "//sections/clause[descendant::terms]".freeze
111
108
 
112
- def term_def_title(title)
113
- case title&.text
114
- when "Terms, definitions, symbols and abbreviated terms"
115
- @labels["termsdefsymbolsabbrev"]
116
- when "Terms, definitions and symbols"
117
- @labels["termsdefsymbols"]
118
- when "Terms, definitions and abbreviated terms"
119
- @labels["termsdefabbrev"]
120
- when "Terms and definitions"
121
- @labels["termsdef"]
122
- else
123
- title
124
- end
125
- end
126
-
127
109
  def terms_defs(isoxml, out, num)
128
110
  f = isoxml.at(ns(TERM_CLAUSE)) or return num
129
111
  out.div **attr_code(id: f["id"]) do |div|
130
112
  num = num + 1
131
- clause_name(num, term_def_title(f&.at(ns("./title"))), div, nil)
113
+ clause_name(num, f&.at(ns("./title")), div, nil)
132
114
  f.elements.each do |e|
133
115
  parse(e, div) unless %w{title source}.include? e.name
134
116
  end
@@ -145,7 +127,7 @@ module IsoDoc::Function
145
127
  f = isoxml.at(ns("//sections/definitions")) or return num
146
128
  out.div **attr_code(id: f["id"], class: "Symbols") do |div|
147
129
  num = num + 1
148
- clause_name(num, f&.at(ns("./title")) || @symbols_lbl, div, nil)
130
+ clause_name(num, f&.at(ns("./title")) || @i18n.symbols, div, nil)
149
131
  f.elements.each do |e|
150
132
  parse(e, div) unless e.name == "title"
151
133
  end
@@ -156,7 +138,7 @@ module IsoDoc::Function
156
138
  # subclause
157
139
  def symbols_parse(isoxml, out)
158
140
  isoxml.at(ns("./title")) or
159
- isoxml.children.first.previous = "<title>#{@symbols_lbl}</title>"
141
+ isoxml.children.first.previous = "<title>#{@i18n.symbols}</title>"
160
142
  clause_parse(isoxml, out)
161
143
  end
162
144
 
@@ -165,7 +147,7 @@ module IsoDoc::Function
165
147
  title_attr = { class: "IntroTitle" }
166
148
  page_break(out)
167
149
  out.div **{ class: "Section3", id: f["id"] } do |div|
168
- clause_name(nil, @introduction_lbl, div, title_attr)
150
+ clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" })
169
151
  f.elements.each do |e|
170
152
  parse(e, div) unless e.name == "title"
171
153
  end
@@ -176,7 +158,9 @@ module IsoDoc::Function
176
158
  f = isoxml.at(ns("//foreword")) || return
177
159
  page_break(out)
178
160
  out.div **attr_code(id: f["id"]) do |s|
179
- s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @foreword_lbl }
161
+ clause_name(nil, f.at(ns("./title")) || @i18n.foreword, s,
162
+ { class: "ForewordTitle" })
163
+ #s.h1(**{ class: "ForewordTitle" }) { |h1| h1 << @i18n.foreword }
180
164
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
181
165
  end
182
166
  end
@@ -197,15 +181,16 @@ module IsoDoc::Function
197
181
  f = isoxml.at(ns("//preface/abstract")) || return
198
182
  page_break(out)
199
183
  out.div **attr_code(id: f["id"]) do |s|
200
- s.h1(**{ class: "AbstractTitle" }) { |h1| h1 << @abstract_lbl }
184
+ clause_name(nil, f.at(ns("./title")), s, { class: "AbstractTitle" })
185
+ #s.h1(**{ class: "AbstractTitle" }) { |h1| h1 << @i18n.abstract }
201
186
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
202
187
  end
203
188
  end
204
189
 
205
190
  def preface(isoxml, out)
206
191
  title_attr = { class: "IntroTitle" }
207
- isoxml.xpath(ns("//preface/clause | //preface/terms | //preface/definitions | "\
208
- "//preface/references")).each do |f|
192
+ isoxml.xpath(ns("//preface/clause | //preface/references | "\
193
+ "//preface/definitions | //preface/terms")).each do |f|
209
194
  page_break(out)
210
195
  out.div **{ class: "Section3", id: f["id"] } do |div|
211
196
  clause_name(nil, f&.at(ns("./title")), div, title_attr)
@@ -2,13 +2,8 @@ module IsoDoc::Function
2
2
  module Table
3
3
 
4
4
  def table_title_parse(node, out)
5
- name = node.at(ns("./name"))
6
- lbl = @xrefs.anchor(node['id'], :label, false)
7
- lbl = nil if labelled_ancestor(node)
8
- return if name.nil? && lbl.nil?
5
+ name = node.at(ns("./name")) or return
9
6
  out.p **{ class: "TableTitle", style: "text-align:center;" } do |p|
10
- lbl.nil? or p << l10n("#{@table_lbl} #{lbl}")
11
- name and !lbl.nil? and p << l10n("&nbsp;&mdash; ")
12
7
  name and name.children.each { |n| parse(n, p) }
13
8
  end
14
9
  end
@@ -1,6 +1,5 @@
1
1
  module IsoDoc::Function
2
2
  module Terms
3
-
4
3
  def definition_parse(node, out)
5
4
  node.children.each { |n| parse(n, out) }
6
5
  end
@@ -13,7 +12,7 @@ module IsoDoc::Function
13
12
 
14
13
  def deprecated_term_parse(node, out)
15
14
  out.p **{ class: "DeprecatedTerms", style:"text-align:left;" } do |p|
16
- p << l10n("#{@deprecated_lbl}: ")
15
+ p << l10n("#{@i18n.deprecated}: ")
17
16
  node.children.each { |c| parse(c, p) }
18
17
  end
19
18
  end
@@ -39,12 +38,19 @@ module IsoDoc::Function
39
38
  end
40
39
  end
41
40
 
41
+ def termnote_delim
42
+ l10n(": ")
43
+ end
44
+
42
45
  def termnote_parse(node, out)
46
+ name = node&.at(ns("./name"))&.remove
43
47
  out.div **note_attrs(node) do |div|
44
- first = node.first_element_child
45
48
  div.p do |p|
46
- p << "#{@xrefs.anchor(node['id'], :label) || '???'}: "
47
- para_then_remainder(first, node, p, div)
49
+ if name
50
+ name.children.each { |n| parse(n, p) }
51
+ p << termnote_delim
52
+ end
53
+ para_then_remainder(node.first_element_child, node, p, div)
48
54
  end
49
55
  end
50
56
  end
@@ -58,8 +64,9 @@ module IsoDoc::Function
58
64
  end
59
65
 
60
66
  def termdef_parse(node, out)
67
+ name = node&.at(ns("./name"))&.remove
61
68
  out.p **{ class: "TermNum", id: node["id"] } do |p|
62
- p << "#{@xrefs.get[node["id"]][:label]}#{clausedelim}"
69
+ name&.children&.each { |n| parse(n, p) }
63
70
  end
64
71
  set_termdomain("")
65
72
  node.children.each { |n| parse(n, out) }
@@ -220,6 +220,7 @@ module IsoDoc::Function
220
220
  when "feedback-statement" then feedback_parse(node, out)
221
221
  when "passthrough" then passthrough_parse(node, out)
222
222
  when "variant" then variant_parse(node, out)
223
+ when "tab" then clausedelimspace(out) # in Presentation XML only
223
224
  else
224
225
  error_parse(node, out)
225
226
  end
@@ -11,7 +11,8 @@ module IsoDoc::Function
11
11
  end
12
12
 
13
13
  def insert_tab(out, n)
14
- [1..n].each { out << '&nbsp; ' }
14
+ tab = %w(Hans Hant).include?(@script) ? "&#x3000;" : "&nbsp; "
15
+ [1..n].each { out << tab }
15
16
  end
16
17
 
17
18
  # add namespaces for Word fragments
@@ -99,8 +100,8 @@ module IsoDoc::Function
99
100
  return '' if array.nil? || array.empty?
100
101
  if array.length == 1 then array[0]
101
102
  else
102
- IsoDoc::Function::I18n::l10n("#{array[0..-2].join(', ')} "\
103
- "#{@and_lbl} #{array.last}",
103
+ @i18n.l10n("#{array[0..-2].join(', ')} "\
104
+ "#{@i18n.and} #{array.last}",
104
105
  @lang, @script)
105
106
  end
106
107
  end
@@ -4,7 +4,6 @@ require "base64"
4
4
  module IsoDoc::HtmlFunction
5
5
  module Html
6
6
  def convert1(docxml, filename, dir)
7
- @xrefs.parse docxml
8
7
  noko do |xml|
9
8
  xml.html **{ lang: "#{@lang}" } do |html|
10
9
  info docxml, nil
@@ -1,29 +1,49 @@
1
1
  require "yaml"
2
2
 
3
3
  # TODO: Cleanup and generalize
4
- module IsoDoc::Function
5
- module I18n
6
- def load_yaml(lang, script)
7
- if @i18nyaml then YAML.load_file(@i18nyaml)
8
- elsif lang == "en"
4
+ module IsoDoc
5
+ class I18n
6
+ def load_yaml(lang, script, i18nyaml = nil)
7
+ ret = load_yaml1(lang, script)
8
+ return ret.merge(YAML.load_file(i18nyaml)) if i18nyaml
9
+ ret
10
+ end
11
+
12
+ def load_yaml1(lang, script)
13
+ if lang == "en"
9
14
  YAML.load_file(File.join(File.dirname(__FILE__),
10
- "../../isodoc-yaml/i18n-en.yaml"))
15
+ "../isodoc-yaml/i18n-en.yaml"))
11
16
  elsif lang == "fr"
12
17
  YAML.load_file(File.join(File.dirname(__FILE__),
13
- "../../isodoc-yaml/i18n-fr.yaml"))
18
+ "../isodoc-yaml/i18n-fr.yaml"))
14
19
  elsif lang == "zh" && script == "Hans"
15
20
  YAML.load_file(File.join(File.dirname(__FILE__),
16
- "../../isodoc-yaml/i18n-zh-Hans.yaml"))
21
+ "../isodoc-yaml/i18n-zh-Hans.yaml"))
17
22
  else
18
23
  YAML.load_file(File.join(File.dirname(__FILE__),
19
- "../../isodoc-yaml/i18n-en.yaml"))
24
+ "../isodoc-yaml/i18n-en.yaml"))
20
25
  end
21
26
  end
22
27
 
23
- def i18n_init(lang, script)
28
+ def get
29
+ @labels
30
+ end
31
+
32
+ def set(x, y)
33
+ @labels[x] = y
34
+ end
35
+
36
+ def initialize(lang, script, i18nyaml = nil)
24
37
  @lang = lang
25
38
  @script = script
26
- y = load_yaml(lang, script)
39
+ y = load_yaml(lang, script, i18nyaml)
40
+ @labels = y
41
+ @labels["language"] = @lang
42
+ @labels["script"] = @script
43
+ @labels.each do |k, v|
44
+ self.class.send(:define_method, k.downcase) { v }
45
+ end
46
+ =begin
27
47
  @term_def_boilerplate = y["term_def_boilerplate"]
28
48
  @scope_lbl = y["scope"]
29
49
  @symbols_lbl = y["symbols"]
@@ -71,30 +91,11 @@ module IsoDoc::Function
71
91
  @requirement_lbl = y["requirement"]
72
92
  @locality = y["locality"]
73
93
  @admonition = y["admonition"]
74
- @labels = y
75
- @labels["language"] = @lang
76
- @labels["script"] = @script
94
+ =end
77
95
  end
78
96
 
79
- # TODO: move to localization file
80
- def eref_localities1_zh(target, type, from, to, delim)
81
- ret = "#{delim} 第#{from.text}" if from
82
- ret += "&ndash;#{to}" if to
83
- loc = (@locality[type] || type.sub(/^locality:/, "").capitalize )
84
- ret += " #{loc}"
85
- ret
86
- end
87
-
88
- # TODO: move to localization file
89
- def eref_localities1(target, type, from, to, delim, lang = "en")
90
- return "" if type == "anchor"
91
- return l10n(eref_localities1_zh(target, type, from, to, delim)) if lang == "zh"
92
- ret = delim
93
- loc = @locality[type] || type.sub(/^locality:/, "").capitalize
94
- ret += " #{loc}"
95
- ret += " #{from.text}" if from
96
- ret += "&ndash;#{to.text}" if to
97
- l10n(ret)
97
+ def self.l10n(x, lang = @lang, script = @script)
98
+ l10n(x, lang, script)
98
99
  end
99
100
 
100
101
  # TODO: move to localization file
@@ -106,8 +107,8 @@ module IsoDoc::Function
106
107
  xml.traverse do |n|
107
108
  next unless n.text?
108
109
  n.replace(n.text.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "、").
109
- gsub(/\(/, "(").gsub(/\)/, ")").
110
- gsub(/\[/, "【").gsub(/\]/, "】"))
110
+ gsub(/\(/, "(").gsub(/\)/, ")").
111
+ gsub(/\[/, "【").gsub(/\]/, "】"))
111
112
  end
112
113
  xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
113
114
  else
@@ -115,7 +116,7 @@ module IsoDoc::Function
115
116
  end
116
117
  end
117
118
 
118
- module_function :l10n
119
+ #module_function :l10n
119
120
 
120
121
  end
121
122
  end