isodoc-i18n 1.5.0 → 1.5.2
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/isodoc/extended_date.rb +37 -8
- data/lib/isodoc/i18n/version.rb +1 -1
- data/lib/isodoc/liquid/liquid.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5323ffdd11fbc3590df89e847850d94952dd14dbedc9a3890f816452c74e5bad
|
|
4
|
+
data.tar.gz: 8de0b46ebe7acfd0e5d63835462f01c672ac6f1a915926b98395ad47b5801a81
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a0c53b89c58f7d898955ed3ad725c5d38d10452787436b52e25a8dca493e6bc33aff19087ce0470098cdffaf52c71df7fdbb5c1eaea488eb96ff576987e470e
|
|
7
|
+
data.tar.gz: 27536a6ebf32c1dafca0da5db856c3215bad6a3a81b1314205a83337290c04bdbca13f75f3d27232085817913152af59072c88a4dfd1fc7a4cd503858d1078c2
|
data/lib/isodoc/extended_date.rb
CHANGED
|
@@ -6,10 +6,15 @@ module IsoDoc
|
|
|
6
6
|
#
|
|
7
7
|
# Adds three POSIX-flavoured surfaces:
|
|
8
8
|
#
|
|
9
|
-
# %E[YyC]
|
|
10
|
-
# %O[mdYy]
|
|
11
|
-
# %_
|
|
12
|
-
#
|
|
9
|
+
# %E[YyC] - era year (calendar-aware)
|
|
10
|
+
# %O[mdYy] - alternative numbering for date components
|
|
11
|
+
# %_ - legacy alias for a literal space (kept for
|
|
12
|
+
# backwards compatibility with IsoDoc::I18n#date)
|
|
13
|
+
#
|
|
14
|
+
# Optional square-bracket-delimited ARGS may follow the conversion letter
|
|
15
|
+
# for %E* and %O* tokens (e.g. +%EY[numeric]+, +%Om[roman]+).
|
|
16
|
+
# Square brackets rather than braces, so format strings remain safe to
|
|
17
|
+
# inline inside Liquid +{{...}}+ templates.
|
|
13
18
|
#
|
|
14
19
|
# The localised name directives (%B, %b, %h, %A, %a, %P, %p) are also
|
|
15
20
|
# routed through the formatter so they pick up CLDR locale data without
|
|
@@ -25,8 +30,8 @@ module IsoDoc
|
|
|
25
30
|
TOKEN_RX = /
|
|
26
31
|
%_ |
|
|
27
32
|
%\^?[BbhPpAa] |
|
|
28
|
-
%E[YyC](?:\
|
|
29
|
-
%O[mdYy](?:\
|
|
33
|
+
%E[YyC](?:\[[^\]]*\])? |
|
|
34
|
+
%O[mdYy](?:\[[^\]]*\])?
|
|
30
35
|
/x.freeze
|
|
31
36
|
|
|
32
37
|
DAY_KEYS = %i[sun mon tue wed thu fri sat].freeze
|
|
@@ -39,6 +44,30 @@ module IsoDoc
|
|
|
39
44
|
new(**opts).format(value, fmt)
|
|
40
45
|
end
|
|
41
46
|
|
|
47
|
+
# Convenience wrapper for ISO 8601 date strings of variable arity
|
|
48
|
+
# (year-only, year-month, or full date). Picks one of three format
|
|
49
|
+
# strings keyed by the arity of the input. Each format string may be
|
|
50
|
+
# nil, in which case the input is returned unchanged for that arity.
|
|
51
|
+
# Used by metanorma-flavour metadata helpers to delegate their
|
|
52
|
+
# arity-branching logic instead of duplicating it per gem.
|
|
53
|
+
def self.format_iso_date(isodate, year: nil, year_month: nil, full: nil,
|
|
54
|
+
**opts)
|
|
55
|
+
normalized, fmt = iso_normalize(isodate, [year, year_month, full])
|
|
56
|
+
return isodate if fmt.nil?
|
|
57
|
+
|
|
58
|
+
format(normalized, fmt, **opts)
|
|
59
|
+
rescue StandardError
|
|
60
|
+
isodate
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.iso_normalize(isodate, fmts)
|
|
64
|
+
return [isodate, nil] if isodate.nil? || isodate.to_s.empty?
|
|
65
|
+
|
|
66
|
+
parts = isodate.to_s.split("-")
|
|
67
|
+
fmt = fmts[parts.size - 1] or return [isodate, nil]
|
|
68
|
+
[[parts[0], parts[1] || "01", parts[2] || "01"].join("-"), fmt]
|
|
69
|
+
end
|
|
70
|
+
|
|
42
71
|
attr_reader :lang, :script
|
|
43
72
|
|
|
44
73
|
def initialize(lang:, script: nil, calendar: nil, calendar_en: nil)
|
|
@@ -90,10 +119,10 @@ module IsoDoc
|
|
|
90
119
|
when /\A%(\^?)([BbhPpAa])\z/
|
|
91
120
|
render_localised_name(time, Regexp.last_match(1) == "^",
|
|
92
121
|
Regexp.last_match(2))
|
|
93
|
-
when /\A%E([YyC])(?:\
|
|
122
|
+
when /\A%E([YyC])(?:\[([^\]]*)\])?\z/
|
|
94
123
|
render_era(time, Regexp.last_match(1),
|
|
95
124
|
parse_args(Regexp.last_match(2)))
|
|
96
|
-
when /\A%O([mdYy])(?:\
|
|
125
|
+
when /\A%O([mdYy])(?:\[([^\]]*)\])?\z/
|
|
97
126
|
render_alt_num(time, Regexp.last_match(1),
|
|
98
127
|
parse_args(Regexp.last_match(2)))
|
|
99
128
|
end
|
data/lib/isodoc/i18n/version.rb
CHANGED
data/lib/isodoc/liquid/liquid.rb
CHANGED
|
@@ -33,6 +33,22 @@ module IsoDoc
|
|
|
33
33
|
grammar = h.merge(parse_hash(infl, symbol: false))
|
|
34
34
|
@@i18n.inflect_ordinal(num.to_i, grammar, "SpelloutRules")
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
# value | date_i18n: fmt[, lang[, calendar]]
|
|
38
|
+
# e.g. "2024-09-30" | date_i18n: "%EY[numeric]年%-m月%-d日", "ja"
|
|
39
|
+
# lang defaults to the i18n instance's lang; calendar to language default.
|
|
40
|
+
def date_i18n(value, fmt, lang = nil, calendar = nil)
|
|
41
|
+
return value if value.nil? || value.to_s.empty?
|
|
42
|
+
|
|
43
|
+
IsoDoc::ExtendedDateFormatter.format(
|
|
44
|
+
value, fmt,
|
|
45
|
+
lang: lang || @@i18n.lang,
|
|
46
|
+
script: lang ? nil : @@i18n.script,
|
|
47
|
+
calendar: calendar
|
|
48
|
+
)
|
|
49
|
+
rescue StandardError
|
|
50
|
+
value
|
|
51
|
+
end
|
|
36
52
|
end
|
|
37
53
|
end
|
|
38
54
|
end
|
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.5.
|
|
4
|
+
version: 1.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|