singleton-cldr-rb 0.0.4 → 0.0.8
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/sgtn-cldr/cldr/localized_date.rb +8 -8
- data/lib/sgtn-cldr/cldr/localized_datetime.rb +5 -11
- data/lib/sgtn-cldr/cldr/localized_str.rb +6 -1
- data/lib/sgtn-cldr/cldr/localized_time.rb +4 -4
- data/lib/sgtn-cldr/formatters/plurals/plural_formatter.rb +38 -0
- data/lib/sgtn-cldr/sgtn-cldr.rb +4 -2
- data/lib/version.rb +1 -1
- data/spec/unit/datetime_spec.rb +18 -18
- data/spec/unit/plural_spec.rb +10 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a11b0c87eda1d838bda30a9593ab573a6317ece76f64301866cf19b14c2e419c
|
4
|
+
data.tar.gz: 9ab8fe0d1d31b8cdfea5b24e67e7cdce6f600a27e3e9921662812a77e99e3af5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe7c170760798d22d64ac439b129a317c039af91d4027927124d4c60203d673ff5c4a5c401f22950ca7866f7fb7ef851c7acedb8eb48e7d7bbe87cb094365320
|
7
|
+
data.tar.gz: 4166be54ecc061b529c9ad21351815bf9c58be9998af2f712bfde006e7efa3b5ea11ea5cda5279a7866150fd20eb16026f498366518afd963013c0206e152d20
|
@@ -2,26 +2,26 @@ require 'date'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
5
|
-
def
|
6
|
-
self.to_datetime().to_date().to_full_s
|
5
|
+
def l_full_s(locale = TwitterCldr.locale)
|
6
|
+
self.to_datetime().localize(locale).to_date().to_full_s
|
7
7
|
end
|
8
8
|
LOCALIZE
|
9
9
|
|
10
10
|
Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
11
|
-
def
|
12
|
-
self.to_datetime().to_date().to_long_s
|
11
|
+
def l_long_s(locale = TwitterCldr.locale)
|
12
|
+
self.to_datetime().localize(locale).to_date().to_long_s
|
13
13
|
end
|
14
14
|
LOCALIZE
|
15
15
|
|
16
16
|
Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
17
|
-
def
|
18
|
-
self.to_datetime().to_date().to_medium_s
|
17
|
+
def l_medium_s(locale = TwitterCldr.locale)
|
18
|
+
self.to_datetime().localize(locale).to_date().to_medium_s
|
19
19
|
end
|
20
20
|
LOCALIZE
|
21
21
|
|
22
22
|
|
23
23
|
Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
24
|
-
def
|
25
|
-
self.to_datetime().to_date().to_short_s
|
24
|
+
def l_short_s(locale = TwitterCldr.locale)
|
25
|
+
self.to_datetime().localize(locale).to_date().to_short_s
|
26
26
|
end
|
27
27
|
LOCALIZE
|
@@ -2,32 +2,26 @@ require 'date'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
5
|
-
def
|
5
|
+
def l_full_s(locale = TwitterCldr.locale)
|
6
6
|
self.localize(locale).to_full_s
|
7
7
|
end
|
8
8
|
LOCALIZE
|
9
9
|
|
10
10
|
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
11
|
-
def
|
11
|
+
def l_long_s(locale = TwitterCldr.locale)
|
12
12
|
self.localize(locale).to_long_s
|
13
13
|
end
|
14
14
|
LOCALIZE
|
15
15
|
|
16
16
|
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
17
|
-
def
|
17
|
+
def l_medium_s(locale = TwitterCldr.locale)
|
18
18
|
self.localize(locale).to_medium_s
|
19
19
|
end
|
20
20
|
LOCALIZE
|
21
21
|
|
22
22
|
|
23
23
|
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
24
|
-
def
|
24
|
+
def l_short_s(locale = TwitterCldr.locale)
|
25
25
|
self.localize(locale).to_short_s
|
26
26
|
end
|
27
|
-
LOCALIZE
|
28
|
-
|
29
|
-
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
30
|
-
def to_date(locale = TwitterCldr.locale)
|
31
|
-
self.localize(locale).to_date
|
32
|
-
end
|
33
|
-
LOCALIZE
|
27
|
+
LOCALIZE
|
@@ -1,6 +1,11 @@
|
|
1
1
|
|
2
2
|
String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
3
3
|
def to_plural_s(locale, arg)
|
4
|
-
|
4
|
+
num_str = SgtnCldr::Formatters::PluralFormatter.new(locale).num_s(self, arg)
|
5
|
+
if num_str.nil? || num_str.empty?
|
6
|
+
self.localize(locale) % arg
|
7
|
+
else
|
8
|
+
num_str
|
9
|
+
end
|
5
10
|
end
|
6
11
|
LOCALIZE
|
@@ -2,26 +2,26 @@ require 'date'
|
|
2
2
|
require 'time'
|
3
3
|
|
4
4
|
Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
5
|
-
def
|
5
|
+
def l_full_s(locale = TwitterCldr.locale)
|
6
6
|
self.localize(locale).to_full_s
|
7
7
|
end
|
8
8
|
LOCALIZE
|
9
9
|
|
10
10
|
Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
11
|
-
def
|
11
|
+
def l_long_s(locale = TwitterCldr.locale)
|
12
12
|
self.localize(locale).to_long_s
|
13
13
|
end
|
14
14
|
LOCALIZE
|
15
15
|
|
16
16
|
Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
17
|
-
def
|
17
|
+
def l_medium_s(locale = TwitterCldr.locale)
|
18
18
|
self.localize(locale).to_medium_s
|
19
19
|
end
|
20
20
|
LOCALIZE
|
21
21
|
|
22
22
|
|
23
23
|
Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
24
|
-
def
|
24
|
+
def l_short_s(locale = TwitterCldr.locale)
|
25
25
|
self.localize(locale).to_short_s
|
26
26
|
end
|
27
27
|
LOCALIZE
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module SgtnCldr
|
4
|
+
module Formatters
|
5
|
+
class PluralFormatter
|
6
|
+
|
7
|
+
attr_reader :locale
|
8
|
+
|
9
|
+
def initialize(locale = TwitterCldr.locale)
|
10
|
+
@locale = TwitterCldr.convert_locale(locale)
|
11
|
+
end
|
12
|
+
|
13
|
+
def num_s(string, replacements)
|
14
|
+
reg = Regexp.union(
|
15
|
+
/%<(\{.*?\})>/
|
16
|
+
)
|
17
|
+
string.gsub(reg) do |match|
|
18
|
+
count_placeholder, patterns = if $1
|
19
|
+
pluralization_hash = JSON.parse($1)
|
20
|
+
if pluralization_hash.is_a?(Hash) && pluralization_hash.size == 1
|
21
|
+
pluralization_hash.first
|
22
|
+
else
|
23
|
+
raise ArgumentError.new('expected a Hash with a single key')
|
24
|
+
end
|
25
|
+
else
|
26
|
+
raise ArgumentError.new('invalide format')
|
27
|
+
end
|
28
|
+
count = replacements[count_placeholder.to_sym].to_s
|
29
|
+
if patterns.is_a?(Hash)
|
30
|
+
return TwitterCldr::Utils.deep_symbolize_keys(patterns)[count.to_sym]
|
31
|
+
else
|
32
|
+
raise ArgumentError.new('expected patterns to be a Hash')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/sgtn-cldr/sgtn-cldr.rb
CHANGED
@@ -3,12 +3,14 @@ module SgtnCldr
|
|
3
3
|
autoload :Cache, "sgtn-cldr/core/cache"
|
4
4
|
end
|
5
5
|
|
6
|
-
autoload :Translation, "sgtn-cldr/api/translation"
|
7
|
-
autoload :Source, "sgtn-cldr/api/source"
|
8
6
|
autoload :Config, "sgtn-cldr/core/config"
|
9
7
|
autoload :Logging, "sgtn-cldr/core/logging"
|
10
8
|
autoload :Exceptions, "sgtn-cldr/core/exceptions"
|
11
9
|
autoload :ValidateUtil, "sgtn-cldr/util/validate-util"
|
10
|
+
|
11
|
+
module Formatters
|
12
|
+
autoload :PluralFormatter, "sgtn-cldr/formatters/plurals/plural_formatter"
|
13
|
+
end
|
12
14
|
|
13
15
|
class << self
|
14
16
|
def configure(options = {}, &block)
|
data/lib/version.rb
CHANGED
data/spec/unit/datetime_spec.rb
CHANGED
@@ -9,34 +9,34 @@ describe SgtnCldr do
|
|
9
9
|
|
10
10
|
it "DateTime" do
|
11
11
|
d = DateTime.new(2007,11,19,8,37,48,"-06:00")
|
12
|
-
expect(d.
|
13
|
-
expect(d.
|
14
|
-
expect(d.
|
15
|
-
expect(d.
|
12
|
+
expect(d.l_full_s(:es)).to eq 'lunes, 19 de noviembre de 2007, 14:37:48 (tiempo universal coordinado)'
|
13
|
+
expect(d.l_long_s(:es)).to eq '19 de noviembre de 2007, 14:37:48 UTC'
|
14
|
+
expect(d.l_medium_s(:es)).to eq '19 nov 2007 14:37:48'
|
15
|
+
expect(d.l_short_s(:es)).to eq '19/11/07 14:37'
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "Date" do
|
19
19
|
d = Date.new(2001,2,3)
|
20
|
-
expect(d.
|
21
|
-
expect(d.
|
22
|
-
expect(d.
|
23
|
-
expect(d.
|
20
|
+
expect(d.l_full_s(:es)).to eq 'sábado, 3 de febrero de 2001'
|
21
|
+
expect(d.l_long_s(:es)).to eq '3 de febrero de 2001'
|
22
|
+
expect(d.l_medium_s(:es)).to eq '3 feb 2001'
|
23
|
+
expect(d.l_short_s(:es)).to eq '3/2/01'
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "DateOfDateTime" do
|
27
27
|
d = DateTime.new(2007,11,19,8,37,48,"-06:00")
|
28
|
-
expect(d.to_date(:es)
|
29
|
-
expect(d.to_date(:es)
|
30
|
-
expect(d.to_date(:es)
|
31
|
-
expect(d.to_date(:es)
|
28
|
+
expect(d.to_date.l_full_s(:es)).to eq 'lunes, 19 de noviembre de 2007'
|
29
|
+
expect(d.to_date.l_long_s(:es)).to eq '19 de noviembre de 2007'
|
30
|
+
expect(d.to_date.l_medium_s(:es)).to eq '19 nov 2007'
|
31
|
+
expect(d.to_date.l_short_s(:es)).to eq '19/11/07'
|
32
32
|
end
|
33
33
|
|
34
34
|
it "time" do
|
35
35
|
d = Time.new(2007,11,1,15,25,0, "+09:00")
|
36
|
-
expect(d.
|
37
|
-
expect(d.
|
38
|
-
expect(d.
|
39
|
-
expect(d.
|
36
|
+
expect(d.l_full_s(:es)).to eq '6:25:00 (tiempo universal coordinado)'
|
37
|
+
expect(d.l_long_s(:es)).to eq '6:25:00 UTC'
|
38
|
+
expect(d.l_medium_s(:es)).to eq '6:25:00'
|
39
|
+
expect(d.l_short_s(:es)).to eq '6:25'
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/spec/unit/plural_spec.rb
CHANGED
@@ -7,13 +7,16 @@ describe SgtnCldr do
|
|
7
7
|
before :each do
|
8
8
|
|
9
9
|
end
|
10
|
-
|
11
|
-
it "
|
12
|
-
str = 'there %<{ "cat_count": { "one": "is one cat", "few": "
|
13
|
-
expect(str.to_plural_s(:
|
14
|
-
expect(str.to_plural_s(:
|
15
|
-
|
10
|
+
|
11
|
+
it "plural" do
|
12
|
+
str = 'there %<{ "cat_count": { "one": "is one cat", "zero":"is no cat", "two": "are two cats", "few": "are some cats", "many": "are many cats", "other": "are %{cat_count} cats" } }> in the room'
|
13
|
+
expect(str.to_plural_s(:cy, { :cat_count => 1 })).to eq 'there is one cat in the room'
|
14
|
+
expect(str.to_plural_s(:cy, { :cat_count => 0 })).to eq 'there is no cat in the room'
|
15
|
+
expect(str.to_plural_s(:cy, { :cat_count => 5 })).to eq 'there are 5 cats in the room'
|
16
|
+
expect(str.to_plural_s(:cy, { :cat_count => 3 })).to eq 'there are some cats in the room'
|
17
|
+
expect(str.to_plural_s(:cy, { :cat_count => 2 })).to eq 'there are two cats in the room'
|
18
|
+
s = '%<{"count": {"0": "no horse", "one": "one horse", "other": "%{count} horses"}}>'
|
19
|
+
expect(s.to_plural_s(:cy, { :count => 0 })).to eq 'no horse'
|
16
20
|
end
|
17
21
|
end
|
18
|
-
|
19
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-cldr-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VMware G11n Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10
|
11
|
+
date: 2021-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- lib/sgtn-cldr/core/exceptions.rb
|
251
251
|
- lib/sgtn-cldr/core/logging.rb
|
252
252
|
- lib/sgtn-cldr/core/request.rb
|
253
|
+
- lib/sgtn-cldr/formatters/plurals/plural_formatter.rb
|
253
254
|
- lib/sgtn-cldr/sgtn-cldr.rb
|
254
255
|
- lib/sgtn-cldr/util/cache-util.rb
|
255
256
|
- lib/sgtn-cldr/util/validate-util.rb
|
@@ -280,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
281
|
- !ruby/object:Gem::Version
|
281
282
|
version: '0'
|
282
283
|
requirements: []
|
283
|
-
rubygems_version: 3.
|
284
|
+
rubygems_version: 3.1.4
|
284
285
|
signing_key:
|
285
286
|
specification_version: 4
|
286
287
|
summary: Singleton cldr for L2 support
|