isodoc-i18n 1.0.0 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cb9429df0523ad853ce2c16221b6ca2da9df7f12be71ec1d9d31dfe8a4507c7
4
- data.tar.gz: 0a454f447146ec95be0a421d3b38844d3c502aabf998cef8dfa9158e731e65de
3
+ metadata.gz: e51e4427e97bf2e0fde14e6f995a35f56771180c5480de0231484927442aa80b
4
+ data.tar.gz: 7516734ee389ab585094598bab5b8ecc696cf488f91cedf1454f192809dcb075
5
5
  SHA512:
6
- metadata.gz: 98607331dc8eea71395667abccf85d4e97ce7c91223ccc1e4b7bb860f596de4262cd642fa94d68693a9e77c61d045c402e6919e71b23a4571e519bc0e6fdcc92
7
- data.tar.gz: e69e12e61a39badb700850998267e473b5acbe51cf3f11de332ed6a08cc6e50b73de8c6811bcb998999b6b07739b78c390368cdeacd5ad4b6dcf97b55787d5f2
6
+ metadata.gz: 876730b932cb38b6fcaa5af50e54b1a7f9b9be6c016ac0f82ad38fd00c0f510a15de812e09be5d733e81a6a16976cf547fc54a9cb113313c82e6762407a2e150
7
+ data.tar.gz: cabf6cd3651fb0314a701d5bb08aafdd607eed4f90d2a2df74d7ea7895e4f90d6566abad20c56e816cdf9c247e865131a7d27cbd2ea258a4e9b171b6afbe9117
@@ -0,0 +1,15 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ uses: metanorma/metanorma-build-scripts/.github/workflows/generic-rake.yml@main
14
+ secrets:
15
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
data/.hound.yml ADDED
@@ -0,0 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ ruby:
4
+ enabled: true
5
+ config_file: .rubocop.yml
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
@@ -100,13 +101,28 @@ module IsoDoc
100
101
  xml.traverse do |n|
101
102
  next unless n.text?
102
103
 
103
- n.replace(cleanup_entities(n.text.gsub(/ /, "").gsub(/:/, ":")
104
- .gsub(/,/, "、").gsub(/\(/, "(").gsub(/\)/, ")")
105
- .gsub(/\[/, "【").gsub(/\]/, "】"), is_xml: false))
104
+ n.replace(cleanup_entities(l10_zh1(n.text), is_xml: false))
106
105
  end
107
106
  xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
108
107
  end
109
108
 
109
+ ZH_CHAR = "\\p{Han}|\\p{In CJK Symbols And Punctuation}|"\
110
+ "\\p{In Halfwidth And Fullwidth Forms}".freeze
111
+
112
+ # note: we can't differentiate comma from enumeration comma 、
113
+ def l10_zh1(text)
114
+ ["::", ",,", ".。", "))", "]】", "::", ";;", "??", "!!"].each do |m|
115
+ text = text.gsub(/(?<=#{ZH_CHAR})#{Regexp.quote m[0]}/, m[1])
116
+ end
117
+ ["((", "[【"].each do |m|
118
+ text = text.gsub(/#{Regexp.quote m[0]}(?=#{ZH_CHAR})/, m[1])
119
+ end
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, "")
124
+ end
125
+
110
126
  def boolean_conj(list, conn)
111
127
  case list.size
112
128
  when 0 then ""
@@ -131,5 +147,32 @@ module IsoDoc
131
147
  c.encode(c.decode(text), :hexadecimal)
132
148
  end
133
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
134
177
  end
135
178
  end
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.0.0".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
+
@@ -48,9 +48,11 @@ RSpec.describe IsoDoc::I18n do
48
48
  it "does Chinese localisation" do
49
49
  c = IsoDoc::I18n.new("zh", "Hans")
50
50
  expect(c.l10n("Code (hello, world.)"))
51
- .to be_equivalent_to "Codehelloworld.)"
52
- expect(c.l10n("<a>Code (he<b>l</b>lo, world.)</a>"))
53
- .to be_equivalent_to "<a>Code(hello、world.)</a>"
51
+ .to be_equivalent_to "Code (hello, world.)"
52
+ expect(c.l10n("计算机代码 (你好, 世界.)"))
53
+ .to be_equivalent_to " 计算机代码(你好,世界。)"
54
+ expect(c.l10n("<a>计算机代码</a> (<b>你好,</b> 世界.)"))
55
+ .to be_equivalent_to "<a>计算机代码</a> (你好, 世界。)"
54
56
  end
55
57
 
56
58
  it "does Hebrew RTL localisation" do
@@ -83,4 +85,18 @@ RSpec.describe IsoDoc::I18n do
83
85
  expect(c.boolean_conj(%w(a b c), "and")).to eq "a, b, and c"
84
86
  expect(c.boolean_conj(%w(a b c d), "and")).to eq "a, b, c, and d"
85
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
86
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.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-03-23 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
@@ -187,6 +201,8 @@ executables: []
187
201
  extensions: []
188
202
  extra_rdoc_files: []
189
203
  files:
204
+ - ".github/workflows/rake.yml"
205
+ - ".hound.yml"
190
206
  - ".rubocop.yml"
191
207
  - CODE_OF_CONDUCT.md
192
208
  - Gemfile
@@ -199,7 +215,9 @@ files:
199
215
  - lib/isodoc-yaml/i18n-en.yaml
200
216
  - lib/isodoc/i18n.rb
201
217
  - lib/isodoc/version.rb
218
+ - spec/assets/de.yaml
202
219
  - spec/assets/new.yaml
220
+ - spec/assets/zh-Hans.yaml
203
221
  - spec/isodoc/base_spec.rb
204
222
  - spec/spec_helper.rb
205
223
  homepage: https://github.com/metanorma/isodoc-i18n