isodoc-i18n 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isodoc/i18n/version.rb +1 -1
- data/lib/isodoc/i18n-yaml.rb +58 -0
- data/lib/isodoc/i18n.rb +28 -59
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03d82802ceebe9b649964369efa5a449b5fa528bb317e327a2683ffd1bcdc502
|
4
|
+
data.tar.gz: 32001c9565f97ce9b2327ba452e7e745317ce7db56cead17c873e70cdd4f49d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 734f890b5868a2a889f91749167a7ea89d050b3bc58d12e1064242b858776c5ad7f793ecfa1d1f58972bf3f12d314996cc5f9ec0afb32614a96a5f6ea5b35674
|
7
|
+
data.tar.gz: 458345fb6eabfc69ec4416444b693ec1b56b07cd28ca994619927ec505c8bba793f161b1f8562a501d42990d56f5a86a1112e5cb9a5af518122696f14f875115
|
data/lib/isodoc/i18n/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "metanorma-utils"
|
3
|
+
|
4
|
+
module IsoDoc
|
5
|
+
class I18n
|
6
|
+
Hash.include Metanorma::Utils::Hash
|
7
|
+
|
8
|
+
def load_yaml(lang, script, i18nyaml = nil, i18nhash = nil)
|
9
|
+
ret = load_yaml1(lang, script)
|
10
|
+
i18nyaml and
|
11
|
+
return normalise_hash(ret.deep_merge(YAML.load_file(i18nyaml)))
|
12
|
+
i18nhash and return normalise_hash(ret.deep_merge(i18nhash))
|
13
|
+
|
14
|
+
normalise_hash(ret)
|
15
|
+
end
|
16
|
+
|
17
|
+
def normalise_hash(ret)
|
18
|
+
case ret
|
19
|
+
when Hash
|
20
|
+
ret.each do |k, v|
|
21
|
+
ret[k] = normalise_hash(v)
|
22
|
+
end
|
23
|
+
ret
|
24
|
+
when Array then ret.map { |n| normalise_hash(n) }
|
25
|
+
when String then cleanup_entities(ret.unicode_normalize(:nfc))
|
26
|
+
else ret
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_yaml1(lang, script)
|
31
|
+
case lang
|
32
|
+
when "zh"
|
33
|
+
if script == "Hans" then load_yaml2("zh-Hans")
|
34
|
+
else load_yaml2("en")
|
35
|
+
end
|
36
|
+
else
|
37
|
+
load_yaml2(lang)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# locally defined in calling class
|
42
|
+
def load_yaml2(lang)
|
43
|
+
YAML.load_file(File.join(File.dirname(__FILE__),
|
44
|
+
"../isodoc-yaml/i18n-#{lang}.yaml"))
|
45
|
+
rescue StandardError
|
46
|
+
YAML.load_file(File.join(File.dirname(__FILE__),
|
47
|
+
"../isodoc-yaml/i18n-en.yaml"))
|
48
|
+
end
|
49
|
+
|
50
|
+
def get
|
51
|
+
@labels
|
52
|
+
end
|
53
|
+
|
54
|
+
def set(key, val)
|
55
|
+
@labels[key] = val
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -1,69 +1,16 @@
|
|
1
|
-
require "yaml"
|
2
1
|
require "htmlentities"
|
3
|
-
require "metanorma-utils"
|
4
2
|
require "twitter_cldr"
|
5
3
|
require_relative "i18n/version"
|
4
|
+
require_relative "i18n-yaml"
|
6
5
|
|
7
6
|
module IsoDoc
|
8
7
|
class I18n
|
9
|
-
Hash.include Metanorma::Utils::Hash
|
10
|
-
|
11
|
-
def load_yaml(lang, script, i18nyaml = nil, i18nhash = nil)
|
12
|
-
ret = load_yaml1(lang, script)
|
13
|
-
i18nyaml and
|
14
|
-
return normalise_hash(ret.deep_merge(YAML.load_file(i18nyaml)))
|
15
|
-
i18nhash and return normalise_hash(ret.deep_merge(i18nhash))
|
16
|
-
|
17
|
-
normalise_hash(ret)
|
18
|
-
end
|
19
|
-
|
20
|
-
def normalise_hash(ret)
|
21
|
-
case ret
|
22
|
-
when Hash
|
23
|
-
ret.each do |k, v|
|
24
|
-
ret[k] = normalise_hash(v)
|
25
|
-
end
|
26
|
-
ret
|
27
|
-
when Array then ret.map { |n| normalise_hash(n) }
|
28
|
-
when String then cleanup_entities(ret.unicode_normalize(:nfc))
|
29
|
-
else ret
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def load_yaml1(lang, script)
|
34
|
-
case lang
|
35
|
-
when "zh"
|
36
|
-
if script == "Hans" then load_yaml2("zh-Hans")
|
37
|
-
else load_yaml2("en")
|
38
|
-
end
|
39
|
-
else
|
40
|
-
load_yaml2(lang)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# locally defined in calling class
|
45
|
-
def load_yaml2(lang)
|
46
|
-
YAML.load_file(File.join(File.dirname(__FILE__),
|
47
|
-
"../isodoc-yaml/i18n-#{lang}.yaml"))
|
48
|
-
rescue StandardError
|
49
|
-
YAML.load_file(File.join(File.dirname(__FILE__),
|
50
|
-
"../isodoc-yaml/i18n-en.yaml"))
|
51
|
-
end
|
52
|
-
|
53
|
-
def get
|
54
|
-
@labels
|
55
|
-
end
|
56
|
-
|
57
|
-
def set(key, val)
|
58
|
-
@labels[key] = val
|
59
|
-
end
|
60
|
-
|
61
8
|
def initialize(lang, script, locale: nil, i18nyaml: nil, i18nhash: nil)
|
62
9
|
@lang = lang
|
63
10
|
@script = script
|
64
11
|
@locale = locale
|
65
|
-
|
66
|
-
@labels =
|
12
|
+
@c = HTMLEntities.new
|
13
|
+
@labels = load_yaml(lang, script, i18nyaml, i18nhash)
|
67
14
|
@labels["language"] = @lang
|
68
15
|
@labels["script"] = @script
|
69
16
|
@labels.each do |k, _v|
|
@@ -158,6 +105,29 @@ module IsoDoc
|
|
158
105
|
text.gsub(/^(:\s)/, "#{colonsp}\\1")
|
159
106
|
end
|
160
107
|
|
108
|
+
def self.cjk_extend(text)
|
109
|
+
cjk_extend(text)
|
110
|
+
end
|
111
|
+
|
112
|
+
def cjk_extend(title)
|
113
|
+
@c.decode(title).chars.map.with_index do |n, i|
|
114
|
+
if i.zero? || !interleave_space_cjk?(title[i - 1] + title[i])
|
115
|
+
n
|
116
|
+
else "\u3000#{n}"
|
117
|
+
end
|
118
|
+
end.join
|
119
|
+
end
|
120
|
+
|
121
|
+
def interleave_space_cjk?(text)
|
122
|
+
text.size == 2 or return
|
123
|
+
["\u2014\u2014", "\u2025\u2025", "\u2026\u2026", "\u22ef\u22ef"].include?(text) ||
|
124
|
+
/\d\d|\p{Latin}\p{Latin}|[[:space:]]/.match?(text) ||
|
125
|
+
/^[\u2018\u201c(\u3014\[{\u3008\u300a\u300c\u300e\u3010\u2985\u3018\u3016\u00ab\u301d]/.match?(text) ||
|
126
|
+
/[\u2019\u201d)\u3015\]}\u3009\u300b\u300d\u300f\u3011\u2986\u3019\u3017\u00bb\u301f]$/.match?(text) ||
|
127
|
+
/[\u3002.\u3001,\u30fb:;\u2010\u301c\u30a0\u2013!?\u203c\u2047\u2048\u2049]/.match?(text) and return false
|
128
|
+
true
|
129
|
+
end
|
130
|
+
|
161
131
|
def boolean_conj(list, conn)
|
162
132
|
case list.size
|
163
133
|
when 0 then ""
|
@@ -177,14 +147,13 @@ module IsoDoc
|
|
177
147
|
end
|
178
148
|
|
179
149
|
def cleanup_entities(text, is_xml: true)
|
180
|
-
c = HTMLEntities.new
|
181
150
|
if is_xml
|
182
151
|
text.split(/([<>])/).each_slice(4).map do |a|
|
183
|
-
a[0] = c.decode(a[0])
|
152
|
+
a[0] = @c.decode(a[0])
|
184
153
|
a
|
185
154
|
end.join
|
186
155
|
else
|
187
|
-
c.decode(text)
|
156
|
+
@c.decode(text)
|
188
157
|
end
|
189
158
|
end
|
190
159
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- isodoc-i18n.gemspec
|
211
211
|
- lib/isodoc-i18n.rb
|
212
212
|
- lib/isodoc-yaml/i18n-en.yaml
|
213
|
+
- lib/isodoc/i18n-yaml.rb
|
213
214
|
- lib/isodoc/i18n.rb
|
214
215
|
- lib/isodoc/i18n/version.rb
|
215
216
|
homepage: https://github.com/metanorma/isodoc-i18n
|