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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a5bee1c4d667fc659d53f3aa964cd4b6dbfe96fd0ec0eb45bce8ba6e44174e7
4
- data.tar.gz: 347381dbea8916642a042f0f2e98505c9418480f0b0b4e7c551610b564638861
3
+ metadata.gz: e51e4427e97bf2e0fde14e6f995a35f56771180c5480de0231484927442aa80b
4
+ data.tar.gz: 7516734ee389ab585094598bab5b8ecc696cf488f91cedf1454f192809dcb075
5
5
  SHA512:
6
- metadata.gz: b74a8ae85c13632ecc7e2619e5c76ae4041278cd73d3f6a2ea6555523b10ff9203c986ab0ffee8e2329f5530df257d2cea845bcdef5841182e48548526f4a898
7
- data.tar.gz: adab36d75979127547ad9bcdfc632a2aed78b2bc7ae2f33616513352a57f940441a5402dff6d72b9a4263ff4cca75233e64cce7102827cd74fd7e02b813e338e
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
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.0.2".freeze
3
+ VERSION = "1.0.3".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,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.2
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 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