csl 2.1.0 → 2.2.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/lib/csl/locale.rb +45 -21
- data/lib/csl/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7f13898b2b1d72d754e5d7a5049b7a65d91f36df7fe68c6db8b369fa2dd21f7
|
4
|
+
data.tar.gz: ee44d0add3174bff091b2575c1c55dd5fcf25a72e63af5823209dc3504beee85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c611c353c05cc66d5cc390d2c09054be36a130648afc9a551ae7dd0e5dc5e497ae598d57a0d97de1ee7c9e8f8f78a6cb4412c2840c9213d2f1bc577d07682148
|
7
|
+
data.tar.gz: ea13a2582afd20235caced2ffeb20f3a5ab11d7e6309a3d134a000c78578f4f2c73b0082ac7552690d8da337fbfb903fd7ec44e035180d2c415a4387d99d8287
|
data/lib/csl/locale.rb
CHANGED
@@ -15,7 +15,7 @@ module CSL
|
|
15
15
|
@extension = '.xml'.freeze
|
16
16
|
@prefix = 'locales-'.freeze
|
17
17
|
|
18
|
-
@tag_pattern = /^[a-z]{2}(-[
|
18
|
+
@tag_pattern = /^[a-z]{2}(-[a-z]{4})?(-[a-z]{2})?|-[a-z]{2}$/i
|
19
19
|
|
20
20
|
# Default languages/regions.
|
21
21
|
# Auto-detection is based on these lists.
|
@@ -29,12 +29,16 @@ module CSL
|
|
29
29
|
AT de BR pt CA en CH de GB en TW zh
|
30
30
|
}.map(&:to_sym)]).freeze
|
31
31
|
|
32
|
+
@scripts = Hash[*%w{
|
33
|
+
sr Latn
|
34
|
+
}.map(&:to_sym)].freeze
|
35
|
+
|
32
36
|
|
33
37
|
class << self
|
34
38
|
include Loader
|
35
39
|
|
36
40
|
attr_accessor :default
|
37
|
-
attr_reader :languages, :regions
|
41
|
+
attr_reader :languages, :regions, :scripts
|
38
42
|
|
39
43
|
def load(input = nil)
|
40
44
|
input ||= Locale.default
|
@@ -42,12 +46,13 @@ module CSL
|
|
42
46
|
super(input)
|
43
47
|
end
|
44
48
|
|
45
|
-
# Normalizes an IETF tag; adds
|
46
|
-
# region's default language.
|
49
|
+
# Normalizes an IETF tag; adds default language, region, script.
|
47
50
|
#
|
48
51
|
# @example
|
49
52
|
# Locale.normalize("en") #-> "en-US"
|
50
53
|
# Locale.normalize("-BR") #-> "pt-BR"
|
54
|
+
# Locale.normalize("de-at") #-> "de-AT"
|
55
|
+
# Locale.normalize("sr") #-> "sr-Latn-RS"
|
51
56
|
#
|
52
57
|
# @raise [ArgumentError] if the passed-in string is no IETF tag
|
53
58
|
#
|
@@ -56,15 +61,32 @@ module CSL
|
|
56
61
|
def normalize(tag)
|
57
62
|
tag = tag.to_s.strip
|
58
63
|
|
59
|
-
|
60
|
-
tag
|
64
|
+
unless tag =~ @tag_pattern
|
65
|
+
raise ArgumentError, "unsupported IETF tag: #{tag.inspect}"
|
66
|
+
end
|
67
|
+
|
68
|
+
language, *rs = tag.split(/-/)
|
69
|
+
region, script = rs.reverse
|
61
70
|
|
62
|
-
language
|
71
|
+
if language.nil? || language.empty?
|
72
|
+
language = languages[region.to_sym]
|
73
|
+
else
|
74
|
+
language.downcase!
|
75
|
+
end
|
63
76
|
|
64
|
-
|
65
|
-
|
77
|
+
if region.nil?
|
78
|
+
region = regions[language.to_sym]
|
79
|
+
else
|
80
|
+
region.upcase!
|
81
|
+
end
|
82
|
+
|
83
|
+
if script.nil?
|
84
|
+
script = scripts[language.to_sym]
|
85
|
+
else
|
86
|
+
script.capitalize!
|
87
|
+
end
|
66
88
|
|
67
|
-
|
89
|
+
[language, script, region].compact.join('-')
|
68
90
|
end
|
69
91
|
end
|
70
92
|
|
@@ -78,7 +100,7 @@ module CSL
|
|
78
100
|
|
79
101
|
has_language
|
80
102
|
|
81
|
-
attr_accessor :region
|
103
|
+
attr_accessor :region, :script
|
82
104
|
|
83
105
|
alias_child :metadata, :info
|
84
106
|
alias_child :dates, :date
|
@@ -181,14 +203,15 @@ module CSL
|
|
181
203
|
#
|
182
204
|
# @return [self]
|
183
205
|
def set(locale)
|
184
|
-
@language,
|
206
|
+
@language, *rs = Locale.normalize(locale).split(/-/).map(&:to_sym)
|
207
|
+
@region, @script = rs.reverse
|
185
208
|
self
|
186
209
|
end
|
187
210
|
|
188
|
-
# Sets the locale's language and region to nil.
|
211
|
+
# Sets the locale's language, script and region to nil.
|
189
212
|
# @return [self]
|
190
213
|
def clear
|
191
|
-
@language, @region = nil
|
214
|
+
@language, @script, @region = nil
|
192
215
|
self
|
193
216
|
end
|
194
217
|
|
@@ -414,11 +437,12 @@ module CSL
|
|
414
437
|
end
|
415
438
|
|
416
439
|
|
417
|
-
# Locales are sorted first by language, then by region
|
418
|
-
# alphabetical with the following exceptions:
|
419
|
-
# prioritised; in case of a language match
|
420
|
-
# language will be prioritised (e.g.,
|
421
|
-
# though the alphabetical order
|
440
|
+
# Locales are sorted first by language, then by region and script;
|
441
|
+
# sort order is alphabetical with the following exceptions:
|
442
|
+
# the default locale is prioritised; in case of a language match
|
443
|
+
# the default region of that language will be prioritised (e.g.,
|
444
|
+
# de-DE will come before de-AT even though the alphabetical order
|
445
|
+
# would be different).
|
422
446
|
#
|
423
447
|
# @param other [Locale] the locale used for comparison
|
424
448
|
# @return [1,0,-1,nil] the result of the comparison
|
@@ -427,7 +451,7 @@ module CSL
|
|
427
451
|
when !other.is_a?(Locale)
|
428
452
|
nil
|
429
453
|
when [language, region] == [other.language, other.region]
|
430
|
-
|
454
|
+
script <=> other.script
|
431
455
|
when default?
|
432
456
|
-1
|
433
457
|
when other.default?
|
@@ -448,7 +472,7 @@ module CSL
|
|
448
472
|
|
449
473
|
# @return [String] the Locale's IETF tag
|
450
474
|
def to_s
|
451
|
-
[language, region].compact.join('-')
|
475
|
+
[language, script, region].compact.join('-')
|
452
476
|
end
|
453
477
|
|
454
478
|
# @return [String] a string representation of the Locale
|
data/lib/csl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-
|
10
|
+
date: 2025-10-16 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: namae
|
@@ -170,7 +169,6 @@ homepage: https://github.com/inukshuk/csl-ruby
|
|
170
169
|
licenses:
|
171
170
|
- BSD-2-Clause
|
172
171
|
metadata: {}
|
173
|
-
post_install_message:
|
174
172
|
rdoc_options: []
|
175
173
|
require_paths:
|
176
174
|
- lib
|
@@ -185,8 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
183
|
- !ruby/object:Gem::Version
|
186
184
|
version: '0'
|
187
185
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
189
|
-
signing_key:
|
186
|
+
rubygems_version: 3.7.2
|
190
187
|
specification_version: 4
|
191
188
|
summary: A Ruby CSL parser and library
|
192
189
|
test_files: []
|