isodoc-i18n 1.5.0 → 1.5.1
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 +13 -8
- data/lib/isodoc/i18n/version.rb +1 -1
- data/lib/isodoc/liquid/liquid.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95f917d7a4996d6dc8305abccafe651027a54240675c991901b9bd918d7d812c
|
|
4
|
+
data.tar.gz: 15b31e27d8b80f12dcbbbab05f191f8f7f04abd4d894f34dc05f3ca91fa47c18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cdd88aa05e6d1fe3021312fe38b0b47dec6343ceb12ff8c56cc920e43aeceb6d9bd58ada246f61fd1f9efa7da0be9df87f51ee25086090ff9eae7cd7ded3ec92
|
|
7
|
+
data.tar.gz: 8a73521429748c13f56c570ddef968974606c69b8ba40be61b456c7ae57dfdd50ea046939784590544ae6a70e6c60757b51d90188bcf5c9b657f48556e01692a
|
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
|
|
@@ -90,10 +95,10 @@ module IsoDoc
|
|
|
90
95
|
when /\A%(\^?)([BbhPpAa])\z/
|
|
91
96
|
render_localised_name(time, Regexp.last_match(1) == "^",
|
|
92
97
|
Regexp.last_match(2))
|
|
93
|
-
when /\A%E([YyC])(?:\
|
|
98
|
+
when /\A%E([YyC])(?:\[([^\]]*)\])?\z/
|
|
94
99
|
render_era(time, Regexp.last_match(1),
|
|
95
100
|
parse_args(Regexp.last_match(2)))
|
|
96
|
-
when /\A%O([mdYy])(?:\
|
|
101
|
+
when /\A%O([mdYy])(?:\[([^\]]*)\])?\z/
|
|
97
102
|
render_alt_num(time, Regexp.last_match(1),
|
|
98
103
|
parse_args(Regexp.last_match(2)))
|
|
99
104
|
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
|