isodoc-i18n 1.0.1 → 1.0.4

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: 3b58388b8a4b834da128338007435231b542c8ba1bb8a132ad60e8d301d0f5d1
4
- data.tar.gz: 1991032f0c7eb5af4f933e48bcb22e24998d0195fb8de477cedb5b40e5010996
3
+ metadata.gz: d9ff88fde8b9dbc8298939de1c1952d05daa8d7651d04c80efa91c36e8b315fe
4
+ data.tar.gz: 86373bc0947b2de749b171a937195ed5e63a095b9346b65a8d3394270784faf6
5
5
  SHA512:
6
- metadata.gz: c448bcb7fc53efca80380ba2a0e1f187114c94c2fba7aa8bb00219bb53adcd1be1a92f1e1858f1dc0626ab0c1de1572221954a044967eb284326ce9e3c0ec483
7
- data.tar.gz: 97cde46c476699cf091b2cb175aac1b578e206df016ed9df17027bf3381c2b1b41451aa3a1c62bae89b4d444037055d3f3b59eefe9978eb2ed9aca23d8ad3a38
6
+ metadata.gz: c62054bd0e4b0af305a0c8ead2a429d2ca7855f283e2f0a257c85be0fcb86d773d8e9da4f518d8985ea2f47a4cb0b493c51900aa595b9dd0c78430a669707488
7
+ data.tar.gz: fcd6eb42c29bf00363526889e28ab49682a0c678fd88ec022c5385fbab5b3c49f84e41e17fe72a34a9b4abf0a93a566351e6f4420c55e94d738b01052bc3567d
data/isodoc-i18n.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "htmlentities", "~> 4.3.4"
26
26
  spec.add_dependency "metanorma-utils", "~> 1.2.8"
27
+ spec.add_dependency "twitter_cldr"
27
28
 
28
29
  spec.add_development_dependency "debug"
29
30
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
data/lib/isodoc/i18n.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "yaml"
2
2
  require "htmlentities"
3
3
  require "metanorma-utils"
4
+ require "twitter_cldr"
4
5
 
5
6
  module IsoDoc
6
7
  class I18n
@@ -117,6 +118,9 @@ module IsoDoc
117
118
  text = text.gsub(/#{Regexp.quote m[0]}(?=#{ZH_CHAR})/, m[1])
118
119
  end
119
120
  text.gsub(/(?<=#{ZH_CHAR}) (?=#{ZH_CHAR})/o, "")
121
+ .gsub(/(?<=\d) (?=#{ZH_CHAR})/o, "")
122
+ .gsub(/(?<=#{ZH_CHAR}) (?=\d)/o, "")
123
+ .gsub(/(?<=#{ZH_CHAR}) (?=[A-Za-z](#{ZH_CHAR}|$))/o, "")
120
124
  end
121
125
 
122
126
  def boolean_conj(list, conn)
@@ -143,5 +147,38 @@ module IsoDoc
143
147
  c.encode(c.decode(text), :hexadecimal)
144
148
  end
145
149
  end
150
+
151
+ # ord class is either SpelloutRules or OrdinalRules
152
+ def inflect_ordinal(num, term, ord_class)
153
+ if @labels["ordinal_keys"].nil? || @labels["ordinal_keys"].empty?
154
+ tw_cldr_localize(num).to_rbnf_s(ord_class, @labels[ord_class])
155
+ else
156
+ tw_cldr_localize(num)
157
+ .to_rbnf_s(ord_class, @labels[ord_class][ordinal_key(term)])
158
+ end
159
+ end
160
+
161
+ def tw_cldr_localize(num)
162
+ num.localize(tw_cldr_lang)
163
+ rescue StandardError
164
+ num.localize(:en)
165
+ end
166
+
167
+ def ordinal_key(term)
168
+ @labels["ordinal_keys"].each_with_object([]) do |k, m|
169
+ m << case k
170
+ when "gender" then term["gender"]
171
+ when "number" then term["number"] || "sg"
172
+ when "case" then term["case"] || "nom"
173
+ end
174
+ end.join(".")
175
+ end
176
+
177
+ def tw_cldr_lang
178
+ if @lang == "zh" && @script == "Hans" then :"zh-cn"
179
+ elsif @lang == "zh" && @script == "Hant" then :"zh-tw"
180
+ else @lang.to_sym
181
+ end
182
+ end
146
183
  end
147
184
  end
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.0.1".freeze
3
+ VERSION = "1.0.4".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ ordinal_keys: [gender,number]
2
+ SpelloutRules:
3
+ m.sg: spellout-ordinal-r
4
+ f.sg: spellout-ordinal
5
+ n.sg: spellout-ordinal-s
6
+ m.pl: spellout-ordinal
7
+ f.pl: spellout-ordinal
8
+ n.pl: spellout-ordinal
9
+ edition: Auflage
10
+ inflection:
11
+ Auflage:
12
+ gender: f
@@ -0,0 +1,7 @@
1
+ ordinal_keys: []
2
+ SpelloutRules: spellout-ordinal
3
+ edition: Auflage
4
+ inflection:
5
+ Auflage:
6
+ gender: f
7
+
@@ -85,4 +85,25 @@ RSpec.describe IsoDoc::I18n do
85
85
  expect(c.boolean_conj(%w(a b c), "and")).to eq "a, b, and c"
86
86
  expect(c.boolean_conj(%w(a b c d), "and")).to eq "a, b, c, and d"
87
87
  end
88
+
89
+ it "does German ordinals" do
90
+ c = IsoDoc::I18n.new("de", "Latn", "spec/assets/de.yaml")
91
+ term = c.inflection[c.edition]
92
+ expect(c.inflect_ordinal(5, term, "SpelloutRules"))
93
+ .to eq "fünfte"
94
+ end
95
+
96
+ it "does Chinese ordinals" do
97
+ c = IsoDoc::I18n.new("zh", "Hans", "spec/assets/zh-Hans.yaml")
98
+ term = c.inflection[c.edition]
99
+ expect(c.inflect_ordinal(5, term, "SpelloutRules"))
100
+ .to eq "第五"
101
+ end
102
+
103
+ it "does Klingon ordinals" do
104
+ c = IsoDoc::I18n.new("tlh", "Hans", "spec/assets/zh-Hans.yaml")
105
+ term = c.inflection[c.edition]
106
+ expect(c.inflect_ordinal(5, term, "SpelloutRules"))
107
+ .to eq "fifth"
108
+ end
88
109
  end
data/spec/spec_helper.rb CHANGED
@@ -30,7 +30,7 @@ def xmlpp(xml)
30
30
  end
31
31
 
32
32
  def metadata(hash)
33
- Hash[hash.sort].delete_if do |_k, v|
33
+ hash.sort.to_h.delete_if do |_k, v|
34
34
  v.nil? || (v.respond_to?(:empty?) && v.empty?)
35
35
  end
36
36
  end
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.0.1
4
+ version: 1.0.4
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-04-05 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: twitter_cldr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: debug
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +215,9 @@ files:
201
215
  - lib/isodoc-yaml/i18n-en.yaml
202
216
  - lib/isodoc/i18n.rb
203
217
  - lib/isodoc/version.rb
218
+ - spec/assets/de.yaml
204
219
  - spec/assets/new.yaml
220
+ - spec/assets/zh-Hans.yaml
205
221
  - spec/isodoc/base_spec.rb
206
222
  - spec/spec_helper.rb
207
223
  homepage: https://github.com/metanorma/isodoc-i18n