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 +4 -4
- data/isodoc-i18n.gemspec +1 -0
- data/lib/isodoc/i18n.rb +37 -0
- data/lib/isodoc/version.rb +1 -1
- data/spec/assets/de.yaml +12 -0
- data/spec/assets/zh-Hans.yaml +7 -0
- data/spec/isodoc/base_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9ff88fde8b9dbc8298939de1c1952d05daa8d7651d04c80efa91c36e8b315fe
|
4
|
+
data.tar.gz: 86373bc0947b2de749b171a937195ed5e63a095b9346b65a8d3394270784faf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/isodoc/version.rb
CHANGED
data/spec/assets/de.yaml
ADDED
@@ -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
|
data/spec/isodoc/base_spec.rb
CHANGED
@@ -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
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.
|
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-
|
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
|