isodoc-i18n 1.1.8 → 1.1.10

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: 03d82802ceebe9b649964369efa5a449b5fa528bb317e327a2683ffd1bcdc502
4
- data.tar.gz: 32001c9565f97ce9b2327ba452e7e745317ce7db56cead17c873e70cdd4f49d3
3
+ metadata.gz: 17fcd1159b3550278a757d9bf50e2fde08d83b1c2be92b14f3ad6789dc509f20
4
+ data.tar.gz: fce8b97a8ac2f5df8754eb62b5994a74a5983098c00c259a5d751da9b30a3f11
5
5
  SHA512:
6
- metadata.gz: 734f890b5868a2a889f91749167a7ea89d050b3bc58d12e1064242b858776c5ad7f793ecfa1d1f58972bf3f12d314996cc5f9ec0afb32614a96a5f6ea5b35674
7
- data.tar.gz: 458345fb6eabfc69ec4416444b693ec1b56b07cd28ca994619927ec505c8bba793f161b1f8562a501d42990d56f5a86a1112e5cb9a5af518122696f14f875115
6
+ metadata.gz: 18cc15dbfc165f6b0428ecb40a804065f1493c7c3fb77dd98a944f6613c8cf18c93920c559b5354eea818f4623d43e6be7dd1c58979556739bd4935811e0f935
7
+ data.tar.gz: 8d1e430afb9e49a7a82868c2987266fac810c0b4bf4e30df2e67965ed3462e5dcaa289199fa9fc29e9bbe306cca427ee6b7c712821c1ec424a1f20dcf548aee3
@@ -0,0 +1,60 @@
1
+ require "date"
2
+
3
+ module IsoDoc
4
+ class I18n
5
+ def date(value, format)
6
+ date_i18n(DateTime.iso8601(value)
7
+ .strftime(convert_date_format(format)))
8
+ end
9
+
10
+ def convert_date_format(fmt)
11
+ fmt.gsub(/%_/, " ")
12
+ .gsub(/%(\^?)([BbhPpAa])/, "%\u200c\\1\\2<%\\2>")
13
+ end
14
+
15
+ def date_i18n(val)
16
+ day_i18n(month_i18n(am_pm_i18n(val)))
17
+ end
18
+
19
+ def am_pm_i18n(val)
20
+ val.gsub(/%\u200cP<am>/, @cal.periods[:am].downcase)
21
+ .gsub(/%\u200cP<pm>/, @cal.periods[:pm].downcase)
22
+ .gsub(/%\u200cp<AM>/, @cal.periods[:am].upcase)
23
+ .gsub(/%\u200cp<PM>/, @cal.periods[:pm].upcase)
24
+ end
25
+
26
+ def month_i18n(val)
27
+ { B: :wide, b: :abbreviated, h: :abbreviated }.each do |f, t|
28
+ @cal_en.calendar_data[:months][:format][t].each do |k, v|
29
+ m = @cal.calendar_data[:months][:format][t][k]
30
+ val.gsub!(/%\u200c#{f}<#{v}>/, m)
31
+ val.gsub!(/%\u200c\^#{f}<#{v}>/, m.upcase)
32
+ end
33
+ end
34
+ val
35
+ end
36
+
37
+ def day_i18n(val)
38
+ { A: :wide, a: :abbreviated }.each do |f, t|
39
+ @cal_en.calendar_data[:days][:format][t].each do |k, v|
40
+ m = @cal.calendar_data[:days][:format][t][k]
41
+ val.gsub!(/%\u200c#{f}<#{v}>/, m)
42
+ val.gsub!(/%\u200c\^#{f}<#{v}>/, m.upcase)
43
+ end
44
+ end
45
+ val
46
+ end
47
+ end
48
+ end
49
+
50
+ # %B - The full month name (``January'')
51
+ # %^B uppercased (``JANUARY'')
52
+ # %b - The abbreviated month name (``Jan'')
53
+ # %^b uppercased (``JAN'')
54
+ # %h - Equivalent to %b
55
+ # %P - Meridian indicator, lowercase (``am'' or ``pm'')
56
+ # %p - Meridian indicator, uppercase (``AM'' or ``PM'')
57
+ # %A - The full weekday name (``Sunday'')
58
+ # %^A uppercased (``SUNDAY'')
59
+ # %a - The abbreviated name (``Sun'')
60
+ # %^a uppercased (``SUN'')
@@ -1,5 +1,5 @@
1
1
  module IsoDoc
2
2
  class I18n
3
- VERSION = "1.1.8".freeze
3
+ VERSION = "1.1.10".freeze
4
4
  end
5
5
  end
data/lib/isodoc/i18n.rb CHANGED
@@ -2,6 +2,7 @@ require "htmlentities"
2
2
  require "twitter_cldr"
3
3
  require_relative "i18n/version"
4
4
  require_relative "i18n-yaml"
5
+ require_relative "date"
5
6
 
6
7
  module IsoDoc
7
8
  class I18n
@@ -9,8 +10,20 @@ module IsoDoc
9
10
  @lang = lang
10
11
  @script = script
11
12
  @locale = locale
13
+ @cal = calendar_data
14
+ @cal_en = TwitterCldr::Shared::Calendar.new(:en)
12
15
  @c = HTMLEntities.new
13
- @labels = load_yaml(lang, script, i18nyaml, i18nhash)
16
+ init_labels(i18nyaml, i18nhash)
17
+ end
18
+
19
+ def calendar_data
20
+ TwitterCldr::Shared::Calendar.new(tw_cldr_lang)
21
+ rescue StandardError
22
+ TwitterCldr::Shared::Calendar.new(:en)
23
+ end
24
+
25
+ def init_labels(i18nyaml, i18nhash)
26
+ @labels = load_yaml(@lang, @script, i18nyaml, i18nhash)
14
27
  @labels["language"] = @lang
15
28
  @labels["script"] = @script
16
29
  @labels.each do |k, _v|
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.8
4
+ version: 1.1.10
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-04-11 00:00:00.000000000 Z
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/date.rb
213
214
  - lib/isodoc/i18n-yaml.rb
214
215
  - lib/isodoc/i18n.rb
215
216
  - lib/isodoc/i18n/version.rb