isodoc-i18n 1.0.6 → 1.1.0
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/.github/workflows/rake.yml +1 -1
- data/.github/workflows/release.yml +24 -0
- data/isodoc-i18n.gemspec +1 -1
- data/lib/isodoc/i18n.rb +36 -8
- data/lib/isodoc/version.rb +1 -1
- data/spec/isodoc/base_spec.rb +21 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71a7b4e2dcb8b00587cc92988c85a99c411444fb8698f8bd067c92a4f90751e2
|
4
|
+
data.tar.gz: 6304cf921c57b555ff259b9c1dfad4d7306e726c7f56f08291e4959a188a6181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9de07fcd21fdfd8ba2ab4d758f76952cbfe84075caad216543cd0a6fa2bcf409fab8e71bc71309aa98ed50342727be9a46c5ffc2625c27f987ede80c65e29b18
|
7
|
+
data.tar.gz: fff4809002eef23c8d550baed4fb1185f134b99fb7a61733d3413045134b11b1e18eaab54a8787e0e4817601ff9051d67ffc1efc97cfaa589a73320188e70d98
|
data/.github/workflows/rake.yml
CHANGED
@@ -0,0 +1,24 @@
|
|
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/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.4.0"
|
27
27
|
spec.add_dependency "twitter_cldr"
|
28
28
|
|
29
29
|
spec.add_development_dependency "debug"
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -54,9 +54,10 @@ module IsoDoc
|
|
54
54
|
@labels[key] = val
|
55
55
|
end
|
56
56
|
|
57
|
-
def initialize(lang, script, i18nyaml: nil, i18nhash: nil)
|
57
|
+
def initialize(lang, script, locale: nil, i18nyaml: nil, i18nhash: nil)
|
58
58
|
@lang = lang
|
59
59
|
@script = script
|
60
|
+
@locale = locale
|
60
61
|
y = load_yaml(lang, script, i18nyaml, i18nhash)
|
61
62
|
@labels = y
|
62
63
|
@labels["language"] = @lang
|
@@ -66,17 +67,16 @@ module IsoDoc
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
|
-
def self.l10n(text, lang = @lang, script = @script)
|
70
|
-
l10n(text, lang, script)
|
70
|
+
def self.l10n(text, lang = @lang, script = @script, locale = @locale)
|
71
|
+
l10n(text, lang, script, locale)
|
71
72
|
end
|
72
73
|
|
73
|
-
# TODO: move to localization file
|
74
74
|
# function localising spaces and punctuation.
|
75
75
|
# Not clear if period needs to be localised for zh
|
76
|
-
def l10n(text, lang = @lang, script = @script)
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
def l10n(text, lang = @lang, script = @script, locale = @locale)
|
77
|
+
lang == "zh" && script == "Hans" and text = l10n_zh(text)
|
78
|
+
lang == "fr" && text = l10n_fr(text, locale || "FR")
|
79
|
+
bidiwrap(text, lang, script)
|
80
80
|
end
|
81
81
|
|
82
82
|
def bidiwrap(text, lang, script)
|
@@ -107,23 +107,51 @@ module IsoDoc
|
|
107
107
|
xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
|
108
108
|
end
|
109
109
|
|
110
|
+
def l10n_fr(text, locale)
|
111
|
+
xml = Nokogiri::HTML::DocumentFragment.parse(text)
|
112
|
+
xml.traverse do |n|
|
113
|
+
next unless n.text?
|
114
|
+
|
115
|
+
n.replace(cleanup_entities(l10n_fr1(n.text, locale), is_xml: false))
|
116
|
+
end
|
117
|
+
xml.to_xml
|
118
|
+
end
|
119
|
+
|
110
120
|
ZH_CHAR = "\\p{Han}|\\p{In CJK Symbols And Punctuation}|"\
|
111
121
|
"\\p{In Halfwidth And Fullwidth Forms}".freeze
|
112
122
|
|
113
123
|
# note: we can't differentiate comma from enumeration comma 、
|
114
124
|
def l10_zh1(text)
|
125
|
+
l10n_zh_remove_space(l10n_zh_punct(text))
|
126
|
+
end
|
127
|
+
|
128
|
+
def l10n_zh_punct(text)
|
115
129
|
["::", ",,", ".。", "))", "]】", "::", ";;", "??", "!!"].each do |m|
|
116
130
|
text = text.gsub(/(?<=#{ZH_CHAR})#{Regexp.quote m[0]}/, m[1])
|
131
|
+
text = text.gsub(/^#{Regexp.quote m[0]}/, m[1])
|
117
132
|
end
|
118
133
|
["((", "[【"].each do |m|
|
119
134
|
text = text.gsub(/#{Regexp.quote m[0]}(?=#{ZH_CHAR})/, m[1])
|
120
135
|
end
|
136
|
+
text
|
137
|
+
end
|
138
|
+
|
139
|
+
def l10n_zh_remove_space(text)
|
121
140
|
text.gsub(/(?<=#{ZH_CHAR}) (?=#{ZH_CHAR})/o, "")
|
122
141
|
.gsub(/(?<=\d) (?=#{ZH_CHAR})/o, "")
|
123
142
|
.gsub(/(?<=#{ZH_CHAR}) (?=\d)/o, "")
|
124
143
|
.gsub(/(?<=#{ZH_CHAR}) (?=[A-Za-z](#{ZH_CHAR}|$))/o, "")
|
125
144
|
end
|
126
145
|
|
146
|
+
def l10n_fr1(text, locale)
|
147
|
+
text = text.gsub(/(?<=\p{Alnum})([»›;?!])/, "\u202f\\1")
|
148
|
+
text = text.gsub(/^([»›;?!])/, "\u202f\\1")
|
149
|
+
text = text.gsub(/([«‹])/, "\\1\u202f")
|
150
|
+
colonsp = locale == "CH" ? "\u202f" : "\u00a0"
|
151
|
+
text = text.gsub(/(?<=\p{Alnum})(:)/, "#{colonsp}\\1")
|
152
|
+
text.gsub(/^(:)/, "#{colonsp}\\1")
|
153
|
+
end
|
154
|
+
|
127
155
|
def boolean_conj(list, conn)
|
128
156
|
case list.size
|
129
157
|
when 0 then ""
|
data/lib/isodoc/version.rb
CHANGED
data/spec/isodoc/base_spec.rb
CHANGED
@@ -38,7 +38,8 @@ RSpec.describe IsoDoc::I18n do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "loads language hash overrides" do
|
41
|
-
c = IsoDoc::I18n.new("en", "Latn",
|
41
|
+
c = IsoDoc::I18n.new("en", "Latn",
|
42
|
+
i18nhash: YAML.load_file("spec/assets/new.yaml"))
|
42
43
|
expect(c.text).to eq "text2"
|
43
44
|
expect(c.at).to eq "at"
|
44
45
|
expect(c.hash.to_s).to be_equivalent_to '{"key1"=>"val1", "key2"=>"val2"}'
|
@@ -85,6 +86,25 @@ RSpec.describe IsoDoc::I18n do
|
|
85
86
|
.to be_equivalent_to "؜Code (hello, world.)؜"
|
86
87
|
end
|
87
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
|
+
end
|
107
|
+
|
88
108
|
it "does boolean conjunctions" do
|
89
109
|
c = IsoDoc::I18n.new("en", "Latn")
|
90
110
|
expect(c.boolean_conj([], "and")).to eq ""
|
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-25 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.4.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.4.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: twitter_cldr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,6 +202,7 @@ extensions: []
|
|
202
202
|
extra_rdoc_files: []
|
203
203
|
files:
|
204
204
|
- ".github/workflows/rake.yml"
|
205
|
+
- ".github/workflows/release.yml"
|
205
206
|
- ".hound.yml"
|
206
207
|
- ".rubocop.yml"
|
207
208
|
- CODE_OF_CONDUCT.md
|
@@ -224,7 +225,7 @@ homepage: https://github.com/metanorma/isodoc-i18n
|
|
224
225
|
licenses:
|
225
226
|
- BSD-2-Clause
|
226
227
|
metadata: {}
|
227
|
-
post_install_message:
|
228
|
+
post_install_message:
|
228
229
|
rdoc_options: []
|
229
230
|
require_paths:
|
230
231
|
- lib
|
@@ -239,8 +240,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
240
|
- !ruby/object:Gem::Version
|
240
241
|
version: '0'
|
241
242
|
requirements: []
|
242
|
-
rubygems_version: 3.
|
243
|
-
signing_key:
|
243
|
+
rubygems_version: 3.1.6
|
244
|
+
signing_key:
|
244
245
|
specification_version: 4
|
245
246
|
summary: isodoc-i18n
|
246
247
|
test_files: []
|