isodoc-i18n 1.1.2 → 1.1.4
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 +7 -7
- data/lib/isodoc/{version.rb → i18n/version.rb} +1 -1
- data/lib/isodoc/i18n.rb +33 -8
- data/lib/isodoc-i18n.rb +0 -4
- metadata +5 -14
- data/.github/workflows/rake.yml +0 -15
- data/.github/workflows/release.yml +0 -24
- data/Rakefile +0 -6
- data/bin/rspec +0 -17
- data/spec/assets/de.yaml +0 -12
- data/spec/assets/new.yaml +0 -7
- data/spec/assets/zh-Hans.yaml +0 -7
- data/spec/isodoc/base_spec.rb +0 -139
- data/spec/spec_helper.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2995acc039a84f2046a7dd94885f6645db44c003e13e3c2d03acc080df6ccf46
|
4
|
+
data.tar.gz: 10aaebe352a542028a9e6bf1d69b3e6d1309416a0fc4329aa34053a520bdc982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9aa2d2786ef223580b0cd832dd08d9821e06553975a369abda5e03b947cff9c5d44ad20ace189937e3707c536ffa99b5090b8cdc8ccf6cbf1dfc429ed0df623
|
7
|
+
data.tar.gz: bd0b5bc0c703ae8ffeeeea6d8df3df34d004bc478b4e8e0ec61c450da83b7c1571954e538bd43a3e7af320035496baa96a27e3d6f564dc7ea5afa58c3244638a
|
data/isodoc-i18n.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "isodoc/version"
|
1
|
+
require_relative "lib/isodoc/i18n/version"
|
4
2
|
|
5
3
|
Gem::Specification.new do |spec|
|
6
4
|
spec.name = "isodoc-i18n"
|
@@ -18,9 +16,11 @@ Gem::Specification.new do |spec|
|
|
18
16
|
|
19
17
|
spec.bindir = "bin"
|
20
18
|
spec.require_paths = ["lib"]
|
21
|
-
spec.files = `git ls-files`.split("\
|
22
|
-
|
23
|
-
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features|bin|.github)/}) \
|
21
|
+
|| f.match(%r{Rakefile|bin/rspec})
|
22
|
+
end
|
23
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
24
24
|
|
25
25
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
26
26
|
spec.add_dependency "metanorma-utils", "~> 1.4.0"
|
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
37
37
|
spec.add_development_dependency "timecop", "~> 0.9"
|
38
38
|
spec.add_development_dependency "webmock"
|
39
|
-
#spec.metadata["rubygems_mfa_required"] = "true"
|
39
|
+
# spec.metadata["rubygems_mfa_required"] = "true"
|
40
40
|
end
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -2,13 +2,17 @@ require "yaml"
|
|
2
2
|
require "htmlentities"
|
3
3
|
require "metanorma-utils"
|
4
4
|
require "twitter_cldr"
|
5
|
+
require_relative "i18n/version"
|
5
6
|
|
6
7
|
module IsoDoc
|
7
8
|
class I18n
|
9
|
+
Hash.include Metanorma::Utils::Hash
|
10
|
+
|
8
11
|
def load_yaml(lang, script, i18nyaml = nil, i18nhash = nil)
|
9
12
|
ret = load_yaml1(lang, script)
|
10
|
-
|
11
|
-
|
13
|
+
i18nyaml and
|
14
|
+
return normalise_hash(ret.deep_merge(YAML.load_file(i18nyaml)))
|
15
|
+
i18nhash and return normalise_hash(ret.deep_merge(i18nhash))
|
12
16
|
|
13
17
|
normalise_hash(ret)
|
14
18
|
end
|
@@ -118,7 +122,7 @@ module IsoDoc
|
|
118
122
|
xml.to_xml(encoding: "UTF-8")
|
119
123
|
end
|
120
124
|
|
121
|
-
ZH_CHAR = "\\p{Han}|\\p{In CJK Symbols And Punctuation}|"\
|
125
|
+
ZH_CHAR = "\\p{Han}|\\p{In CJK Symbols And Punctuation}|" \
|
122
126
|
"\\p{In Halfwidth And Fullwidth Forms}".freeze
|
123
127
|
|
124
128
|
# note: we can't differentiate comma from enumeration comma 、
|
@@ -196,13 +200,21 @@ module IsoDoc
|
|
196
200
|
num.localize(:en)
|
197
201
|
end
|
198
202
|
|
203
|
+
INFLECTIONS = {
|
204
|
+
number: "sg",
|
205
|
+
case: "nom",
|
206
|
+
gender: "masc",
|
207
|
+
person: "3rd",
|
208
|
+
voice: "act",
|
209
|
+
mood: "ind",
|
210
|
+
tense: "pres",
|
211
|
+
}.freeze
|
212
|
+
|
213
|
+
INFLECTION_ORDER = %i(voice mood tense number case gender person).freeze
|
214
|
+
|
199
215
|
def ordinal_key(term)
|
200
216
|
@labels["ordinal_keys"].each_with_object([]) do |k, m|
|
201
|
-
m <<
|
202
|
-
when "gender" then term["gender"]
|
203
|
-
when "number" then term["number"] || "sg"
|
204
|
-
when "case" then term["case"] || "nom"
|
205
|
-
end
|
217
|
+
m << (term[k] || INFLECTIONS[k.to_sym])
|
206
218
|
end.join(".")
|
207
219
|
end
|
208
220
|
|
@@ -212,5 +224,18 @@ module IsoDoc
|
|
212
224
|
else @lang.to_sym
|
213
225
|
end
|
214
226
|
end
|
227
|
+
|
228
|
+
# can skip category if not present
|
229
|
+
def inflect(word, options)
|
230
|
+
i = @labels.dig("inflection", word) or return word
|
231
|
+
i.is_a? String and return i
|
232
|
+
|
233
|
+
INFLECTION_ORDER.each do |x|
|
234
|
+
infl = options[x] || INFLECTIONS[x]
|
235
|
+
i = i[infl] if i[infl]
|
236
|
+
i.is_a? String and return i
|
237
|
+
end
|
238
|
+
word
|
239
|
+
end
|
215
240
|
end
|
216
241
|
end
|
data/lib/isodoc-i18n.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.1.
|
4
|
+
version: 1.1.4
|
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-09
|
11
|
+
date: 2022-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -201,26 +201,17 @@ executables: []
|
|
201
201
|
extensions: []
|
202
202
|
extra_rdoc_files: []
|
203
203
|
files:
|
204
|
-
- ".github/workflows/rake.yml"
|
205
|
-
- ".github/workflows/release.yml"
|
206
204
|
- ".hound.yml"
|
207
205
|
- ".rubocop.yml"
|
208
206
|
- CODE_OF_CONDUCT.md
|
209
207
|
- Gemfile
|
210
208
|
- LICENSE
|
211
209
|
- README.adoc
|
212
|
-
- Rakefile
|
213
|
-
- bin/rspec
|
214
210
|
- isodoc-i18n.gemspec
|
215
211
|
- lib/isodoc-i18n.rb
|
216
212
|
- lib/isodoc-yaml/i18n-en.yaml
|
217
213
|
- lib/isodoc/i18n.rb
|
218
|
-
- lib/isodoc/version.rb
|
219
|
-
- spec/assets/de.yaml
|
220
|
-
- spec/assets/new.yaml
|
221
|
-
- spec/assets/zh-Hans.yaml
|
222
|
-
- spec/isodoc/base_spec.rb
|
223
|
-
- spec/spec_helper.rb
|
214
|
+
- lib/isodoc/i18n/version.rb
|
224
215
|
homepage: https://github.com/metanorma/isodoc-i18n
|
225
216
|
licenses:
|
226
217
|
- BSD-2-Clause
|
@@ -233,14 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
224
|
requirements:
|
234
225
|
- - ">="
|
235
226
|
- !ruby/object:Gem::Version
|
236
|
-
version: 2.
|
227
|
+
version: 2.7.0
|
237
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
229
|
requirements:
|
239
230
|
- - ">="
|
240
231
|
- !ruby/object:Gem::Version
|
241
232
|
version: '0'
|
242
233
|
requirements: []
|
243
|
-
rubygems_version: 3.
|
234
|
+
rubygems_version: 3.3.7
|
244
235
|
signing_key:
|
245
236
|
specification_version: 4
|
246
237
|
summary: isodoc-i18n
|
data/.github/workflows/rake.yml
DELETED
@@ -1,15 +0,0 @@
|
|
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/ci/.github/workflows/generic-rake.yml@main
|
14
|
-
secrets:
|
15
|
-
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
-
# See https://github.com/metanorma/cimas
|
3
|
-
name: release
|
4
|
-
|
5
|
-
on:
|
6
|
-
workflow_dispatch:
|
7
|
-
inputs:
|
8
|
-
next_version:
|
9
|
-
description: |
|
10
|
-
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
|
11
|
-
required: true
|
12
|
-
default: 'skip'
|
13
|
-
push:
|
14
|
-
tags: [ v* ]
|
15
|
-
|
16
|
-
jobs:
|
17
|
-
release:
|
18
|
-
uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
|
19
|
-
with:
|
20
|
-
next_version: ${{ github.event.inputs.next_version }}
|
21
|
-
secrets:
|
22
|
-
rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
|
23
|
-
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
24
|
-
|
data/Rakefile
DELETED
data/bin/rspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# This file was generated by Bundler.
|
4
|
-
#
|
5
|
-
# The application 'rspec' is installed as part of a gem, and
|
6
|
-
# this file is here to facilitate running it.
|
7
|
-
#
|
8
|
-
|
9
|
-
require "pathname"
|
10
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
|
11
|
-
"../../Gemfile", Pathname.new(__FILE__).realpath
|
12
|
-
)
|
13
|
-
|
14
|
-
require "rubygems"
|
15
|
-
require "bundler/setup"
|
16
|
-
|
17
|
-
load Gem.bin_path("rspec-core", "rspec")
|
data/spec/assets/de.yaml
DELETED
@@ -1,12 +0,0 @@
|
|
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/assets/new.yaml
DELETED
data/spec/assets/zh-Hans.yaml
DELETED
data/spec/isodoc/base_spec.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe IsoDoc::I18n do
|
4
|
-
it "has a version number" do
|
5
|
-
expect(IsoDoc::I18n::VERSION).not_to be nil
|
6
|
-
end
|
7
|
-
|
8
|
-
it "loads language files" do
|
9
|
-
c = IsoDoc::I18n.new("en", "Latn")
|
10
|
-
expect(c.text).to eq "text"
|
11
|
-
expect(c.at).to eq "at"
|
12
|
-
expect(c.language).to eq "en"
|
13
|
-
expect(c.script).to eq "Latn"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "manipulates i18n class" do
|
17
|
-
c = IsoDoc::I18n.new("en", "Latn")
|
18
|
-
expect(c.get["text"]).to eq "text"
|
19
|
-
expect(c.get["fred"]).to be_nil
|
20
|
-
c.set("fred", "frederic")
|
21
|
-
expect(c.get["fred"]).to eq "frederic"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "loads default for missing language files" do
|
25
|
-
c = IsoDoc::I18n.new("tlh", "Klin")
|
26
|
-
expect(c.text).to eq "text"
|
27
|
-
expect(c.at).to eq "at"
|
28
|
-
expect(c.language).to eq "tlh"
|
29
|
-
expect(c.script).to eq "Klin"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "loads language file overrides" do
|
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",
|
42
|
-
i18nhash: YAML.load_file("spec/assets/new.yaml"))
|
43
|
-
expect(c.text).to eq "text2"
|
44
|
-
expect(c.at).to eq "at"
|
45
|
-
expect(c.hash.to_s).to be_equivalent_to '{"key1"=>"val1", "key2"=>"val2"}'
|
46
|
-
expect(c.arr.to_s).to eq '["arr1", "arr2"]'
|
47
|
-
end
|
48
|
-
|
49
|
-
it "does English localisation" do
|
50
|
-
c = IsoDoc::I18n.new("en", "Latn")
|
51
|
-
expect(c.l10n("Code (hello, world.)"))
|
52
|
-
.to be_equivalent_to "Code (hello, world.)"
|
53
|
-
expect(c.l10n("<a>Code (he<b>l</b>lo, world.)</a>"))
|
54
|
-
.to be_equivalent_to "<a>Code (he<b>l</b>lo, world.)</a>"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "does Chinese localisation" do
|
58
|
-
c = IsoDoc::I18n.new("zh", "Hans")
|
59
|
-
expect(c.l10n("Code (hello, world.)"))
|
60
|
-
.to be_equivalent_to "Code (hello, world.)"
|
61
|
-
expect(c.l10n("计算机代码 (你好, 世界.)"))
|
62
|
-
.to be_equivalent_to " 计算机代码(你好,世界。)"
|
63
|
-
expect(c.l10n("<a>计算机代码</a> (<b>你好,</b> 世界.)"))
|
64
|
-
.to be_equivalent_to "<a>计算机代码</a> (你好, 世界。)"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "does Hebrew RTL localisation" do
|
68
|
-
c = IsoDoc::I18n.new("en", "Hebr")
|
69
|
-
expect(c.l10n("Code (hello, world.)"))
|
70
|
-
.to be_equivalent_to "Code (hello, world.)"
|
71
|
-
expect(c.l10n("Code (hello, world.)", "en", "Latn"))
|
72
|
-
.to be_equivalent_to "‎Code (hello, world.)‎"
|
73
|
-
c = IsoDoc::I18n.new("en", "Latn")
|
74
|
-
expect(c.l10n("Code (hello, world.)", "en", "Hebr"))
|
75
|
-
.to be_equivalent_to "‏Code (hello, world.)‏"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "does Arabic RTL localisation" do
|
79
|
-
c = IsoDoc::I18n.new("en", "Arab")
|
80
|
-
expect(c.l10n("Code (hello, world.)"))
|
81
|
-
.to be_equivalent_to "Code (hello, world.)"
|
82
|
-
expect(c.l10n("Code (hello, world.)", "en", "Latn"))
|
83
|
-
.to be_equivalent_to "‎Code (hello, world.)‎"
|
84
|
-
c = IsoDoc::I18n.new("en", "Latn")
|
85
|
-
expect(c.l10n("Code (hello, world.)", "en", "Arab"))
|
86
|
-
.to be_equivalent_to "؜Code (hello, world.)؜"
|
87
|
-
end
|
88
|
-
|
89
|
-
it "does French localisation" do
|
90
|
-
e = HTMLEntities.new
|
91
|
-
c = IsoDoc::I18n.new("fr", "Latn")
|
92
|
-
expect(e.encode(c.l10n("Code; «code» and: code!"), :hexadecimal))
|
93
|
-
.to be_equivalent_to "Code ; « code » "\
|
94
|
-
"and : code !"
|
95
|
-
expect(e.encode(c.l10n("Code; «code» and: code!"), :hexadecimal))
|
96
|
-
.to be_equivalent_to "Code ; « code » "\
|
97
|
-
"and : code !"
|
98
|
-
c = IsoDoc::I18n.new("fr", "Latn", locale: "FR")
|
99
|
-
expect(e.encode(c.l10n("Code; «code» and: code!"), :hexadecimal))
|
100
|
-
.to be_equivalent_to "Code ; « code » "\
|
101
|
-
"and : code !"
|
102
|
-
c = IsoDoc::I18n.new("fr", "Latn", locale: "CH")
|
103
|
-
expect(e.encode(c.l10n("Code; «code» and: code!"), :hexadecimal))
|
104
|
-
.to be_equivalent_to "Code ; « code » "\
|
105
|
-
"and : code !"
|
106
|
-
expect(e.encode(c.l10n("http://xyz a;b"), :hexadecimal))
|
107
|
-
.to be_equivalent_to "http://xyz a;b"
|
108
|
-
end
|
109
|
-
|
110
|
-
it "does boolean conjunctions" do
|
111
|
-
c = IsoDoc::I18n.new("en", "Latn")
|
112
|
-
expect(c.boolean_conj([], "and")).to eq ""
|
113
|
-
expect(c.boolean_conj(%w(a), "and")).to eq "a"
|
114
|
-
expect(c.boolean_conj(%w(a b), "and")).to eq "a and b"
|
115
|
-
expect(c.boolean_conj(%w(a b c), "and")).to eq "a, b, and c"
|
116
|
-
expect(c.boolean_conj(%w(a b c d), "and")).to eq "a, b, c, and d"
|
117
|
-
end
|
118
|
-
|
119
|
-
it "does German ordinals" do
|
120
|
-
c = IsoDoc::I18n.new("de", "Latn", i18nyaml: "spec/assets/de.yaml")
|
121
|
-
term = c.inflection[c.edition]
|
122
|
-
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
123
|
-
.to eq "fünfte"
|
124
|
-
end
|
125
|
-
|
126
|
-
it "does Chinese ordinals" do
|
127
|
-
c = IsoDoc::I18n.new("zh", "Hans", i18nyaml: "spec/assets/zh-Hans.yaml")
|
128
|
-
term = c.inflection[c.edition]
|
129
|
-
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
130
|
-
.to eq "第五"
|
131
|
-
end
|
132
|
-
|
133
|
-
it "does Klingon ordinals" do
|
134
|
-
c = IsoDoc::I18n.new("tlh", "Hans", i18nyaml: "spec/assets/zh-Hans.yaml")
|
135
|
-
term = c.inflection[c.edition]
|
136
|
-
expect(c.inflect_ordinal(5, term, "SpelloutRules"))
|
137
|
-
.to eq "fifth"
|
138
|
-
end
|
139
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require "simplecov"
|
2
|
-
SimpleCov.start do
|
3
|
-
add_filter "/spec/"
|
4
|
-
end
|
5
|
-
|
6
|
-
require "bundler/setup"
|
7
|
-
require "isodoc-i18n"
|
8
|
-
require "rspec/matchers"
|
9
|
-
require "equivalent-xml"
|
10
|
-
require "rexml/document"
|
11
|
-
|
12
|
-
RSpec.configure do |config|
|
13
|
-
# Enable flags like --only-failures and --next-failure
|
14
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
15
|
-
|
16
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
17
|
-
config.disable_monkey_patching!
|
18
|
-
|
19
|
-
config.expect_with :rspec do |c|
|
20
|
-
c.syntax = :expect
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def xmlpp(xml)
|
25
|
-
s = ""
|
26
|
-
f = REXML::Formatters::Pretty.new(2)
|
27
|
-
f.compact = true
|
28
|
-
f.write(REXML::Document.new(xml), s)
|
29
|
-
s
|
30
|
-
end
|
31
|
-
|
32
|
-
def metadata(hash)
|
33
|
-
hash.sort.to_h.delete_if do |_k, v|
|
34
|
-
v.nil? || (v.respond_to?(:empty?) && v.empty?)
|
35
|
-
end
|
36
|
-
end
|