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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7698b9379cd9b2bfea54973ec2cdaef465b92963e2e6e38715d20ef50edf58c1
4
- data.tar.gz: c6370d69fcc7c5a5301b98582538853f29c6bd9455082b1b2e2e0b882e3ec0f3
3
+ metadata.gz: 95f917d7a4996d6dc8305abccafe651027a54240675c991901b9bd918d7d812c
4
+ data.tar.gz: 15b31e27d8b80f12dcbbbab05f191f8f7f04abd4d894f34dc05f3ca91fa47c18
5
5
  SHA512:
6
- metadata.gz: 7815dca37d2d415d53afe5a41260f650d8ff8f5b61a5d1fe200d0ad8de4fb008813f9e0737ceca81abf30c9dad15bd341c2e4db478787ff55d34a9901ef15b9b
7
- data.tar.gz: 58f22f0df18829864fac021c3cb7e66c7d520c82eb92c385ecde375005341f27bb9f6546f8e4f4963f57826b05328bcb1cc4ba7fec11928a153002261d5b08a7
6
+ metadata.gz: cdd88aa05e6d1fe3021312fe38b0b47dec6343ceb12ff8c56cc920e43aeceb6d9bd58ada246f61fd1f9efa7da0be9df87f51ee25086090ff9eae7cd7ded3ec92
7
+ data.tar.gz: 8a73521429748c13f56c570ddef968974606c69b8ba40be61b456c7ae57dfdd50ea046939784590544ae6a70e6c60757b51d90188bcf5c9b657f48556e01692a
@@ -6,10 +6,15 @@ module IsoDoc
6
6
  #
7
7
  # Adds three POSIX-flavoured surfaces:
8
8
  #
9
- # %E[YyC](?:\{ARGS\})? - era year (calendar-aware)
10
- # %O[mdYy](?:\{ARGS\})? - alternative numbering for date components
11
- # %_ - legacy alias for a literal space (kept for
12
- # backwards compatibility with IsoDoc::I18n#date)
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])(?:\{([^}]*)\})?\z/
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])(?:\{([^}]*)\})?\z/
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
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.5.0".freeze
3
+ VERSION = "1.5.1".freeze
4
4
  end
5
5
  end
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.