isodoc-i18n 1.0.3 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/isodoc-i18n.gemspec +1 -1
- data/lib/isodoc/i18n.rb +12 -5
- data/lib/isodoc/version.rb +1 -1
- data/spec/isodoc/base_spec.rb +18 -3
- data/spec/spec_helper.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40bf798e8180b8b3014f6822a1ac8e5336728231d1436dbfe74c49fd54326551
|
4
|
+
data.tar.gz: d41acbc509af8a536d02fc3e4fd0511972b61e8730eb47d43d1520b0efd9e000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16aa8550bf43b723bd10576d86be8a371d7fe88cb4967ccd3a88f295f695a6fce19830b250ad587b6a968fee2f8bd4c11cfa37c34c6d49ff7a15ef4544426fe3
|
7
|
+
data.tar.gz: 6e0ddd03856d58eed0655f1c978adaec56442eca6c378da15b81c21fd4177be1daf573d157f63da82d21364b7b10c59df726a0cf10cbfe2c87104e25a0e88adb
|
data/isodoc-i18n.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
24
24
|
|
25
25
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
26
|
-
spec.add_dependency "metanorma-utils", "~> 1.
|
26
|
+
spec.add_dependency "metanorma-utils", "~> 1.3.0"
|
27
27
|
spec.add_dependency "twitter_cldr"
|
28
28
|
|
29
29
|
spec.add_development_dependency "debug"
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -5,9 +5,10 @@ require "twitter_cldr"
|
|
5
5
|
|
6
6
|
module IsoDoc
|
7
7
|
class I18n
|
8
|
-
def load_yaml(lang, script, i18nyaml = nil)
|
8
|
+
def load_yaml(lang, script, i18nyaml = nil, i18nhash = nil)
|
9
9
|
ret = load_yaml1(lang, script)
|
10
10
|
return normalise_hash(ret.merge(YAML.load_file(i18nyaml))) if i18nyaml
|
11
|
+
return normalise_hash(ret.merge(i18nhash)) if i18nhash
|
11
12
|
|
12
13
|
normalise_hash(ret)
|
13
14
|
end
|
@@ -53,10 +54,10 @@ module IsoDoc
|
|
53
54
|
@labels[key] = val
|
54
55
|
end
|
55
56
|
|
56
|
-
def initialize(lang, script, i18nyaml
|
57
|
+
def initialize(lang, script, i18nyaml: nil, i18nhash: nil)
|
57
58
|
@lang = lang
|
58
59
|
@script = script
|
59
|
-
y = load_yaml(lang, script, i18nyaml)
|
60
|
+
y = load_yaml(lang, script, i18nyaml, i18nhash)
|
60
61
|
@labels = y
|
61
62
|
@labels["language"] = @lang
|
62
63
|
@labels["script"] = @script
|
@@ -151,13 +152,19 @@ module IsoDoc
|
|
151
152
|
# ord class is either SpelloutRules or OrdinalRules
|
152
153
|
def inflect_ordinal(num, term, ord_class)
|
153
154
|
if @labels["ordinal_keys"].nil? || @labels["ordinal_keys"].empty?
|
154
|
-
num
|
155
|
+
tw_cldr_localize(num).to_rbnf_s(ord_class, @labels[ord_class])
|
155
156
|
else
|
156
|
-
num
|
157
|
+
tw_cldr_localize(num)
|
157
158
|
.to_rbnf_s(ord_class, @labels[ord_class][ordinal_key(term)])
|
158
159
|
end
|
159
160
|
end
|
160
161
|
|
162
|
+
def tw_cldr_localize(num)
|
163
|
+
num.localize(tw_cldr_lang)
|
164
|
+
rescue StandardError
|
165
|
+
num.localize(:en)
|
166
|
+
end
|
167
|
+
|
161
168
|
def ordinal_key(term)
|
162
169
|
@labels["ordinal_keys"].each_with_object([]) do |k, m|
|
163
170
|
m << case k
|
data/lib/isodoc/version.rb
CHANGED
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"}'
|
@@ -87,16 +95,23 @@ RSpec.describe IsoDoc::I18n do
|
|
87
95
|
end
|
88
96
|
|
89
97
|
it "does German ordinals" do
|
90
|
-
c = IsoDoc::I18n.new("de", "Latn", "spec/assets/de.yaml")
|
98
|
+
c = IsoDoc::I18n.new("de", "Latn", i18nyaml: "spec/assets/de.yaml")
|
91
99
|
term = c.inflection[c.edition]
|
92
100
|
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
93
101
|
.to eq "fünfte"
|
94
102
|
end
|
95
103
|
|
96
104
|
it "does Chinese ordinals" do
|
97
|
-
c = IsoDoc::I18n.new("zh", "Hans", "spec/assets/zh-Hans.yaml")
|
105
|
+
c = IsoDoc::I18n.new("zh", "Hans", i18nyaml: "spec/assets/zh-Hans.yaml")
|
98
106
|
term = c.inflection[c.edition]
|
99
107
|
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
100
108
|
.to eq "第五"
|
101
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
|
102
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.6
|
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-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.3.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.
|
40
|
+
version: 1.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: twitter_cldr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
239
|
- !ruby/object:Gem::Version
|
240
240
|
version: '0'
|
241
241
|
requirements: []
|
242
|
-
rubygems_version: 3.3.
|
242
|
+
rubygems_version: 3.3.16
|
243
243
|
signing_key:
|
244
244
|
specification_version: 4
|
245
245
|
summary: isodoc-i18n
|