isodoc-i18n 1.1.7 → 1.1.9
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 +40 -58
- 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: e6ff9dd68aee9f2481e2c3b3efb12eb227d534841dd30ac23fa7402f64a3ffd2
|
4
|
+
data.tar.gz: 5b6b0bd8eb4b8323cf8650a5dba48c966226f2898ac812beb5f5b3f31cd91b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3333a3f5386017bf62a88d8b82597477702965cf7aa9505b00927dd883420cb3a881363774a07311653703316d2f591ad1bb8b2f21d485b034ad2d9356d6544
|
7
|
+
data.tar.gz: b980154492673ddd83d2cd3c90fcde55856a14e055f493df0372cc627ffd2602a197c2e3ccb0680e3c942c058540551634f4c3a7d7c51c0ba9eb77f35d422c18
|
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,29 @@
|
|
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"
|
5
|
+
require_relative "date"
|
6
6
|
|
7
7
|
module IsoDoc
|
8
8
|
class I18n
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
9
|
+
def initialize(lang, script, locale: nil, i18nyaml: nil, i18nhash: nil)
|
10
|
+
@lang = lang
|
11
|
+
@script = script
|
12
|
+
@locale = locale
|
13
|
+
@cal = calendar_data
|
14
|
+
@cal_en = TwitterCldr::Shared::Calendar.new(:en)
|
15
|
+
@c = HTMLEntities.new
|
16
|
+
init_labels(i18nyaml, i18nhash)
|
42
17
|
end
|
43
18
|
|
44
|
-
|
45
|
-
|
46
|
-
YAML.load_file(File.join(File.dirname(__FILE__),
|
47
|
-
"../isodoc-yaml/i18n-#{lang}.yaml"))
|
19
|
+
def calendar_data
|
20
|
+
TwitterCldr::Shared::Calendar.new(tw_cldr_lang)
|
48
21
|
rescue StandardError
|
49
|
-
|
50
|
-
"../isodoc-yaml/i18n-en.yaml"))
|
22
|
+
TwitterCldr::Shared::Calendar.new(:en)
|
51
23
|
end
|
52
24
|
|
53
|
-
def
|
54
|
-
@labels
|
55
|
-
end
|
56
|
-
|
57
|
-
def set(key, val)
|
58
|
-
@labels[key] = val
|
59
|
-
end
|
60
|
-
|
61
|
-
def initialize(lang, script, locale: nil, i18nyaml: nil, i18nhash: nil)
|
62
|
-
@lang = lang
|
63
|
-
@script = script
|
64
|
-
@locale = locale
|
65
|
-
y = load_yaml(lang, script, i18nyaml, i18nhash)
|
66
|
-
@labels = y
|
25
|
+
def init_labels(i18nyaml, i18nhash)
|
26
|
+
@labels = load_yaml(@lang, @script, i18nyaml, i18nhash)
|
67
27
|
@labels["language"] = @lang
|
68
28
|
@labels["script"] = @script
|
69
29
|
@labels.each do |k, _v|
|
@@ -158,6 +118,29 @@ module IsoDoc
|
|
158
118
|
text.gsub(/^(:\s)/, "#{colonsp}\\1")
|
159
119
|
end
|
160
120
|
|
121
|
+
def self.cjk_extend(text)
|
122
|
+
cjk_extend(text)
|
123
|
+
end
|
124
|
+
|
125
|
+
def cjk_extend(title)
|
126
|
+
@c.decode(title).chars.map.with_index do |n, i|
|
127
|
+
if i.zero? || !interleave_space_cjk?(title[i - 1] + title[i])
|
128
|
+
n
|
129
|
+
else "\u3000#{n}"
|
130
|
+
end
|
131
|
+
end.join
|
132
|
+
end
|
133
|
+
|
134
|
+
def interleave_space_cjk?(text)
|
135
|
+
text.size == 2 or return
|
136
|
+
["\u2014\u2014", "\u2025\u2025", "\u2026\u2026", "\u22ef\u22ef"].include?(text) ||
|
137
|
+
/\d\d|\p{Latin}\p{Latin}|[[:space:]]/.match?(text) ||
|
138
|
+
/^[\u2018\u201c(\u3014\[{\u3008\u300a\u300c\u300e\u3010\u2985\u3018\u3016\u00ab\u301d]/.match?(text) ||
|
139
|
+
/[\u2019\u201d)\u3015\]}\u3009\u300b\u300d\u300f\u3011\u2986\u3019\u3017\u00bb\u301f]$/.match?(text) ||
|
140
|
+
/[\u3002.\u3001,\u30fb:;\u2010\u301c\u30a0\u2013!?\u203c\u2047\u2048\u2049]/.match?(text) and return false
|
141
|
+
true
|
142
|
+
end
|
143
|
+
|
161
144
|
def boolean_conj(list, conn)
|
162
145
|
case list.size
|
163
146
|
when 0 then ""
|
@@ -177,14 +160,13 @@ module IsoDoc
|
|
177
160
|
end
|
178
161
|
|
179
162
|
def cleanup_entities(text, is_xml: true)
|
180
|
-
c = HTMLEntities.new
|
181
163
|
if is_xml
|
182
164
|
text.split(/([<>])/).each_slice(4).map do |a|
|
183
|
-
a[0] = c.decode(a[0])
|
165
|
+
a[0] = @c.decode(a[0])
|
184
166
|
a
|
185
167
|
end.join
|
186
168
|
else
|
187
|
-
c.decode(text)
|
169
|
+
@c.decode(text)
|
188
170
|
end
|
189
171
|
end
|
190
172
|
|
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.9
|
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-06-04 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
|