isodoc-i18n 1.0.2 → 1.0.3
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 +28 -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 +14 -0
- 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: e51e4427e97bf2e0fde14e6f995a35f56771180c5480de0231484927442aa80b
|
4
|
+
data.tar.gz: 7516734ee389ab585094598bab5b8ecc696cf488f91cedf1454f192809dcb075
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876730b932cb38b6fcaa5af50e54b1a7f9b9be6c016ac0f82ad38fd00c0f510a15de812e09be5d733e81a6a16976cf547fc54a9cb113313c82e6762407a2e150
|
7
|
+
data.tar.gz: cabf6cd3651fb0314a701d5bb08aafdd607eed4f90d2a2df74d7ea7895e4f90d6566abad20c56e816cdf9c247e865131a7d27cbd2ea258a4e9b171b6afbe9117
|
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
|
@@ -146,5 +147,32 @@ module IsoDoc
|
|
146
147
|
c.encode(c.decode(text), :hexadecimal)
|
147
148
|
end
|
148
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
|
+
num.localize(tw_cldr_lang).to_rbnf_s(ord_class, @labels[ord_class])
|
155
|
+
else
|
156
|
+
num.localize(tw_cldr_lang)
|
157
|
+
.to_rbnf_s(ord_class, @labels[ord_class][ordinal_key(term)])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def ordinal_key(term)
|
162
|
+
@labels["ordinal_keys"].each_with_object([]) do |k, m|
|
163
|
+
m << case k
|
164
|
+
when "gender" then term["gender"]
|
165
|
+
when "number" then term["number"] || "sg"
|
166
|
+
when "case" then term["case"] || "nom"
|
167
|
+
end
|
168
|
+
end.join(".")
|
169
|
+
end
|
170
|
+
|
171
|
+
def tw_cldr_lang
|
172
|
+
if @lang == "zh" && @script == "Hans" then :"zh-cn"
|
173
|
+
elsif @lang == "zh" && @script == "Hant" then :"zh-tw"
|
174
|
+
else @lang.to_sym
|
175
|
+
end
|
176
|
+
end
|
149
177
|
end
|
150
178
|
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,18 @@ 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
|
88
102
|
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.
|
4
|
+
version: 1.0.3
|
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
|