isodoc-i18n 1.1.4 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2995acc039a84f2046a7dd94885f6645db44c003e13e3c2d03acc080df6ccf46
4
- data.tar.gz: 10aaebe352a542028a9e6bf1d69b3e6d1309416a0fc4329aa34053a520bdc982
3
+ metadata.gz: 12cac5aeb35b5ef95804ecb4ccde36d048613feb1120030518f7b2cc1d8c92b5
4
+ data.tar.gz: e91952a59254cc33d11339955ee050f6bc8761d80fa59d91d8c1e0c7f4889cdd
5
5
  SHA512:
6
- metadata.gz: f9aa2d2786ef223580b0cd832dd08d9821e06553975a369abda5e03b947cff9c5d44ad20ace189937e3707c536ffa99b5090b8cdc8ccf6cbf1dfc429ed0df623
7
- data.tar.gz: bd0b5bc0c703ae8ffeeeea6d8df3df34d004bc478b4e8e0ec61c450da83b7c1571954e538bd43a3e7af320035496baa96a27e3d6f564dc7ea5afa58c3244638a
6
+ metadata.gz: 61311452a113779cbe5c0e5971d5bca2b5f1f14fbfda11056abd073ebcf188aa21cef54620a64ef15f896df0b3016e22df76a1474ba5d71c3fddea8fb2fea16d
7
+ data.tar.gz: 84c4275111d86ff51c6547e821e976910766a0803ff38685b8c053197da8259c2ebbb4031e5dc89aeb86ed9fe8f4be9c8bf92c4baab3ae4cc5e5f8b2404a8adf
data/isodoc-i18n.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
24
24
 
25
25
  spec.add_dependency "htmlentities", "~> 4.3.4"
26
- spec.add_dependency "metanorma-utils", "~> 1.4.0"
26
+ spec.add_dependency "metanorma-utils", ">= 1.5.0"
27
27
  spec.add_dependency "twitter_cldr"
28
28
 
29
29
  spec.add_development_dependency "debug"
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.1.4".freeze
3
+ VERSION = "1.1.7".freeze
4
4
  end
5
5
  end
data/lib/isodoc/i18n.rb CHANGED
@@ -78,7 +78,7 @@ module IsoDoc
78
78
  # function localising spaces and punctuation.
79
79
  # Not clear if period needs to be localised for zh
80
80
  def l10n(text, lang = @lang, script = @script, locale = @locale)
81
- lang == "zh" && script == "Hans" and text = l10n_zh(text)
81
+ lang == "zh" and text = l10n_zh(text, script)
82
82
  lang == "fr" && text = l10n_fr(text, locale || "FR")
83
83
  bidiwrap(text, lang, script)
84
84
  end
@@ -101,12 +101,12 @@ module IsoDoc
101
101
  .default_script(@lang))]
102
102
  end
103
103
 
104
- def l10n_zh(text)
104
+ def l10n_zh(text, script = "Hans")
105
105
  xml = Nokogiri::XML::DocumentFragment.parse(text)
106
106
  xml.traverse do |n|
107
107
  next unless n.text?
108
108
 
109
- n.replace(cleanup_entities(l10_zh1(n.text), is_xml: false))
109
+ n.replace(l10_zh1(cleanup_entities(n.text, is_xml: false), script))
110
110
  end
111
111
  xml.to_xml(encoding: "UTF-8").gsub(/<b>/, "").gsub("</b>", "")
112
112
  .gsub(/<\?[^>]+>/, "")
@@ -117,7 +117,7 @@ module IsoDoc
117
117
  xml.traverse do |n|
118
118
  next unless n.text?
119
119
 
120
- n.replace(cleanup_entities(l10n_fr1(n.text, locale), is_xml: false))
120
+ n.replace(l10n_fr1(cleanup_entities(n.text, is_xml: false), locale))
121
121
  end
122
122
  xml.to_xml(encoding: "UTF-8")
123
123
  end
@@ -126,17 +126,16 @@ module IsoDoc
126
126
  "\\p{In Halfwidth And Fullwidth Forms}".freeze
127
127
 
128
128
  # note: we can't differentiate comma from enumeration comma 、
129
- def l10_zh1(text)
129
+ def l10_zh1(text, _script)
130
130
  l10n_zh_remove_space(l10n_zh_punct(text))
131
131
  end
132
132
 
133
133
  def l10n_zh_punct(text)
134
- ["::", ",,", ".。", "))", "]", "::", ";;", "??", "!!"].each do |m|
135
- text = text.gsub(/(?<=#{ZH_CHAR})#{Regexp.quote m[0]}/, m[1])
136
- text = text.gsub(/^#{Regexp.quote m[0]}/, m[1])
134
+ ["::", ",,", "..", "))", "]", "::", ";;", "??", "!!", "–~"].each do |m|
135
+ text = text.gsub(/#{Regexp.quote m[0]}/, m[1])
137
136
  end
138
- ["((", "["].each do |m|
139
- text = text.gsub(/#{Regexp.quote m[0]}(?=#{ZH_CHAR})/, m[1])
137
+ ["((", "["].each do |m|
138
+ text = text.gsub(/#{Regexp.quote m[0]}/, m[1])
140
139
  end
141
140
  text
142
141
  end
@@ -167,11 +166,16 @@ module IsoDoc
167
166
  .sub(/%2/, list[1])
168
167
  else
169
168
  @labels["multiple_#{conn}"]
170
- .sub(/%1/, l10n(list[0..-2].join(", "), @lang, @script))
169
+ .sub(/%1/, l10n(list[0..-2].join(enum_comma), @lang, @script))
171
170
  .sub(/%2/, list[-1])
172
171
  end
173
172
  end
174
173
 
174
+ def enum_comma
175
+ %w(Hans Hant).include?(@script) and return "、"
176
+ ", "
177
+ end
178
+
175
179
  def cleanup_entities(text, is_xml: true)
176
180
  c = HTMLEntities.new
177
181
  if is_xml
@@ -186,12 +190,13 @@ module IsoDoc
186
190
 
187
191
  # ord class is either SpelloutRules or OrdinalRules
188
192
  def inflect_ordinal(num, term, ord_class)
189
- if @labels["ordinal_keys"].nil? || @labels["ordinal_keys"].empty?
190
- tw_cldr_localize(num).to_rbnf_s(ord_class, @labels[ord_class])
191
- else
192
- tw_cldr_localize(num)
193
- .to_rbnf_s(ord_class, @labels[ord_class][ordinal_key(term)])
194
- end
193
+ lbl = if @labels["ordinal_keys"].nil? || @labels["ordinal_keys"].empty?
194
+ @labels[ord_class]
195
+ else @labels[ord_class][ordinal_key(term)]
196
+ end
197
+ tw_cldr_localize(num).to_rbnf_s(ord_class, lbl)
198
+ rescue StandardError
199
+ num.localize(@lang.to_sym).to_rbnf_s(ord_class, lbl)
195
200
  end
196
201
 
197
202
  def tw_cldr_localize(num)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-09 00:00:00.000000000 Z
11
+ date: 2023-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: metanorma-utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.0
33
+ version: 1.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.0
40
+ version: 1.5.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: twitter_cldr
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  - !ruby/object:Gem::Version
232
232
  version: '0'
233
233
  requirements: []
234
- rubygems_version: 3.3.7
234
+ rubygems_version: 3.3.26
235
235
  signing_key:
236
236
  specification_version: 4
237
237
  summary: isodoc-i18n