isodoc-i18n 1.0.2 → 1.0.5
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 +38 -3
- 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 +30 -1
- 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: '0702006206028e38503e71c72fc5763c9ddc78798c7db38485ce3db8d1c58b55'
|
4
|
+
data.tar.gz: d55ddad57f401360969c491fc1c8efaa0a375324a09b1a2e1afee31bf9e76156
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fa9c7108157ebf3e63d7bcba97e37b878527593d4462356d5f23e4d6350da37bb76e173ae165e75a86b025d5b09a193f0cde80505f50a47a5c3396e5323ff41
|
7
|
+
data.tar.gz: 30673e7993504c760358ef70aa18352eae6f5455098f5e86e07080af51fadd68014bc826f056bc5c28908e59651611a4ee4bdf7e2fed953f2bd03e38d050df8c
|
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,12 +1,14 @@
|
|
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
|
7
|
-
def load_yaml(lang, script, i18nyaml = nil)
|
8
|
+
def load_yaml(lang, script, i18nyaml = nil, i18nhash = nil)
|
8
9
|
ret = load_yaml1(lang, script)
|
9
10
|
return normalise_hash(ret.merge(YAML.load_file(i18nyaml))) if i18nyaml
|
11
|
+
return normalise_hash(ret.merge(i18nhash)) if i18nhash
|
10
12
|
|
11
13
|
normalise_hash(ret)
|
12
14
|
end
|
@@ -52,10 +54,10 @@ module IsoDoc
|
|
52
54
|
@labels[key] = val
|
53
55
|
end
|
54
56
|
|
55
|
-
def initialize(lang, script, i18nyaml
|
57
|
+
def initialize(lang, script, i18nyaml: nil, i18nhash: nil)
|
56
58
|
@lang = lang
|
57
59
|
@script = script
|
58
|
-
y = load_yaml(lang, script, i18nyaml)
|
60
|
+
y = load_yaml(lang, script, i18nyaml, i18nhash)
|
59
61
|
@labels = y
|
60
62
|
@labels["language"] = @lang
|
61
63
|
@labels["script"] = @script
|
@@ -146,5 +148,38 @@ module IsoDoc
|
|
146
148
|
c.encode(c.decode(text), :hexadecimal)
|
147
149
|
end
|
148
150
|
end
|
151
|
+
|
152
|
+
# ord class is either SpelloutRules or OrdinalRules
|
153
|
+
def inflect_ordinal(num, term, ord_class)
|
154
|
+
if @labels["ordinal_keys"].nil? || @labels["ordinal_keys"].empty?
|
155
|
+
tw_cldr_localize(num).to_rbnf_s(ord_class, @labels[ord_class])
|
156
|
+
else
|
157
|
+
tw_cldr_localize(num)
|
158
|
+
.to_rbnf_s(ord_class, @labels[ord_class][ordinal_key(term)])
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def tw_cldr_localize(num)
|
163
|
+
num.localize(tw_cldr_lang)
|
164
|
+
rescue StandardError
|
165
|
+
num.localize(:en)
|
166
|
+
end
|
167
|
+
|
168
|
+
def ordinal_key(term)
|
169
|
+
@labels["ordinal_keys"].each_with_object([]) do |k, m|
|
170
|
+
m << case k
|
171
|
+
when "gender" then term["gender"]
|
172
|
+
when "number" then term["number"] || "sg"
|
173
|
+
when "case" then term["case"] || "nom"
|
174
|
+
end
|
175
|
+
end.join(".")
|
176
|
+
end
|
177
|
+
|
178
|
+
def tw_cldr_lang
|
179
|
+
if @lang == "zh" && @script == "Hans" then :"zh-cn"
|
180
|
+
elsif @lang == "zh" && @script == "Hant" then :"zh-tw"
|
181
|
+
else @lang.to_sym
|
182
|
+
end
|
183
|
+
end
|
149
184
|
end
|
150
185
|
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
@@ -30,7 +30,15 @@ RSpec.describe IsoDoc::I18n do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "loads language file overrides" do
|
33
|
-
c = IsoDoc::I18n.new("en", "Latn", "spec/assets/new.yaml")
|
33
|
+
c = IsoDoc::I18n.new("en", "Latn", i18nyaml: "spec/assets/new.yaml")
|
34
|
+
expect(c.text).to eq "text2"
|
35
|
+
expect(c.at).to eq "at"
|
36
|
+
expect(c.hash.to_s).to be_equivalent_to '{"key1"=>"val1", "key2"=>"val2"}'
|
37
|
+
expect(c.arr.to_s).to eq '["arr1", "arr2"]'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "loads language hash overrides" do
|
41
|
+
c = IsoDoc::I18n.new("en", "Latn", i18nhash: YAML.load_file("spec/assets/new.yaml"))
|
34
42
|
expect(c.text).to eq "text2"
|
35
43
|
expect(c.at).to eq "at"
|
36
44
|
expect(c.hash.to_s).to be_equivalent_to '{"key1"=>"val1", "key2"=>"val2"}'
|
@@ -85,4 +93,25 @@ RSpec.describe IsoDoc::I18n do
|
|
85
93
|
expect(c.boolean_conj(%w(a b c), "and")).to eq "a, b, and c"
|
86
94
|
expect(c.boolean_conj(%w(a b c d), "and")).to eq "a, b, c, and d"
|
87
95
|
end
|
96
|
+
|
97
|
+
it "does German ordinals" do
|
98
|
+
c = IsoDoc::I18n.new("de", "Latn", i18nyaml: "spec/assets/de.yaml")
|
99
|
+
term = c.inflection[c.edition]
|
100
|
+
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
101
|
+
.to eq "fünfte"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "does Chinese ordinals" do
|
105
|
+
c = IsoDoc::I18n.new("zh", "Hans", i18nyaml: "spec/assets/zh-Hans.yaml")
|
106
|
+
term = c.inflection[c.edition]
|
107
|
+
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
108
|
+
.to eq "第五"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "does Klingon ordinals" do
|
112
|
+
c = IsoDoc::I18n.new("tlh", "Hans", i18nyaml: "spec/assets/zh-Hans.yaml")
|
113
|
+
term = c.inflection[c.edition]
|
114
|
+
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
115
|
+
.to eq "fifth"
|
116
|
+
end
|
88
117
|
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.5
|
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
|
+
date: 2022-05-06 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
|