r18n-core 2.1.8 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +9 -0
- data/README.md +2 -2
- data/Rakefile +0 -2
- data/lib/r18n-core/locale.rb +3 -2
- data/lib/r18n-core/translated_string.rb +7 -2
- data/lib/r18n-core/translation.rb +1 -1
- data/lib/r18n-core/version.rb +1 -1
- data/locales/en-gb.rb +3 -1
- data/locales/en.rb +1 -1
- data/spec/locale_spec.rb +28 -0
- data/spec/r18n_spec.rb +2 -2
- data/spec/translation_spec.rb +20 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710530bf79e2d31499094507a16c89fecda6c4be
|
4
|
+
data.tar.gz: 2fd094bdbc14d67b78bddb7b827ce384f16320c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e65ed82bdf22bdce12a170f7ac84512a8b9ad6d7c758bc090da96a03f9d0ccdf2038c81e33da1669c54847c1babcd85d4744a142d7f8d967d0162deb89e5efc
|
7
|
+
data.tar.gz: d6b7573f5739b1723681a9aab973a8acf816b9fdbfd22233bf724b214eeadcb71096ee77b4f40478f3195631649eb2713a178175573c3fa95d3ae67e7a8eb46e
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## 2.2 (La Habana)
|
4
|
+
* Change date format in `en` locale to `YYYY-MM-DD` (by Alexander Popov).
|
5
|
+
* Add `TranslatedString#as_json` for ActiveSupport compatibility (by Tim Craft).
|
6
|
+
* Fix `TranslatedString#html_safe?` behaviour (by Tim Craft).
|
7
|
+
* Fix unsupported `LANG` environment (by Chris Poirier).
|
8
|
+
* Fix `Locale#localize` method for `DateTime` objects (by Alexander Popov).s
|
9
|
+
|
1
10
|
## 2.1.8 (Ѣ)
|
2
11
|
* Fix `true` and `false` keys support (by Alexander Popov).
|
3
12
|
|
data/README.md
CHANGED
@@ -324,8 +324,8 @@ R18n has some built-in time formats for locales: `:human`, `:full` and
|
|
324
324
|
```ruby
|
325
325
|
l Time.now, :human #=> "now"
|
326
326
|
l Time.now, :full #=> "August 9th, 2009 21:47"
|
327
|
-
l Time.now #=> "08
|
328
|
-
l Time.now.to_date #=> "08
|
327
|
+
l Time.now #=> "2009-08-09 21:41"
|
328
|
+
l Time.now.to_date #=> "2009-08-09"
|
329
329
|
```
|
330
330
|
|
331
331
|
### Model
|
data/Rakefile
CHANGED
data/lib/r18n-core/locale.rb
CHANGED
@@ -159,7 +159,7 @@ module R18n
|
|
159
159
|
return month_standalone[obj.month - 1] if :month == format
|
160
160
|
return obj.to_s if :human == format and not params.first.is_a? I18n
|
161
161
|
|
162
|
-
type = obj.is_a?(Date) ? 'date' : 'time'
|
162
|
+
type = obj.is_a?(Date) && !obj.is_a?(DateTime) ? 'date' : 'time'
|
163
163
|
format = :standard unless format
|
164
164
|
|
165
165
|
unless [:human, :full, :standard].include? format
|
@@ -224,7 +224,8 @@ module R18n
|
|
224
224
|
# “yesterday”. In +now+ you can set base time, which be used to get relative
|
225
225
|
# time. For special cases you can replace it in locale’s class.
|
226
226
|
def format_time_human(time, i18n, now = Time.now, *params)
|
227
|
-
|
227
|
+
diff = time - now
|
228
|
+
minutes = time.is_a?(DateTime) ? diff * 24 * 60.0 : diff / 60.0
|
228
229
|
diff = minutes.abs
|
229
230
|
if (diff > 24 * 60) or (time.mday != now.mday and diff > 12 * 24)
|
230
231
|
format_time(format_date_human(time.to_date, i18n, now.to_date), time)
|
@@ -45,9 +45,9 @@ module R18n
|
|
45
45
|
true
|
46
46
|
end
|
47
47
|
|
48
|
-
#
|
48
|
+
# Return true if `html_safe` method is defined, otherwise false.
|
49
49
|
def html_safe?
|
50
|
-
|
50
|
+
respond_to? :html_safe
|
51
51
|
end
|
52
52
|
|
53
53
|
# Override to_s to make string html safe if `html_safe` method is defined.
|
@@ -59,6 +59,11 @@ module R18n
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# Define `as_json` for ActiveSupport compatibility.
|
63
|
+
def as_json(options = nil)
|
64
|
+
to_str
|
65
|
+
end
|
66
|
+
|
62
67
|
# Override marshal_dump to avoid Marshalizing filter procs
|
63
68
|
def _dump(limit)
|
64
69
|
[@locale.code, @path, to_str].join(":")
|
@@ -83,7 +83,7 @@ module R18n
|
|
83
83
|
# Add another hash with +translations+ for some +locale+. Current data is
|
84
84
|
# more priority, that new one in +translations+.
|
85
85
|
def merge!(translations, locale)
|
86
|
-
translations.each_pair do |name, value|
|
86
|
+
(translations || { }).each_pair do |name, value|
|
87
87
|
if not @data.has_key? name
|
88
88
|
path = @path.empty? ? name : "#{@path}.#{name}"
|
89
89
|
case value
|
data/lib/r18n-core/version.rb
CHANGED
data/locales/en-gb.rb
CHANGED
data/locales/en.rb
CHANGED
data/spec/locale_spec.rb
CHANGED
@@ -131,6 +131,34 @@ describe R18n::Locale do
|
|
131
131
|
'1st of January, 1969 00:00')
|
132
132
|
end
|
133
133
|
|
134
|
+
it "localizes date-times for human" do
|
135
|
+
day = 1.0
|
136
|
+
hour = day / 24
|
137
|
+
minute = hour / 60
|
138
|
+
second = minute / 60
|
139
|
+
zero = DateTime.new(1970)
|
140
|
+
p = [:human, R18n::I18n.new('en'), zero]
|
141
|
+
|
142
|
+
expect(@en.localize( zero + 7 * day, *p)).to eq('8th of January 00:00')
|
143
|
+
expect(@en.localize( zero + 50 * hour, *p)).to eq('after 2 days 02:00')
|
144
|
+
expect(@en.localize( zero + 25 * hour, *p)).to eq('tomorrow 01:00')
|
145
|
+
expect(@en.localize( zero + 70 * minute, *p)).to eq('after 1 hour')
|
146
|
+
expect(@en.localize( zero + hour, *p)).to eq('after 1 hour')
|
147
|
+
expect(@en.localize( zero + 38 * minute, *p)).to eq('after 38 minutes')
|
148
|
+
expect(@en.localize( zero + 5 * second, *p)).to eq('now')
|
149
|
+
expect(@en.localize( zero - 15 * second, *p)).to eq('now')
|
150
|
+
expect(@en.localize( zero - minute, *p)).to eq('1 minute ago')
|
151
|
+
expect(@en.localize( zero - hour + 59 * second, *p)).to eq('59 minutes ago')
|
152
|
+
expect(@en.localize( zero - 2 * hour, *p)).to eq('2 hours ago')
|
153
|
+
expect(@en.localize( zero - 13 * hour, *p)).to eq('yesterday 11:00')
|
154
|
+
expect(@en.localize( zero - 50 * hour, *p)).to eq('3 days ago 22:00')
|
155
|
+
|
156
|
+
expect(@en.localize( zero - 9 * day, *p)).to eq(
|
157
|
+
'23rd of December, 1969 00:00')
|
158
|
+
expect(@en.localize( zero - 365 * day, *p)).to eq(
|
159
|
+
'1st of January, 1969 00:00')
|
160
|
+
end
|
161
|
+
|
134
162
|
it "uses standard formatter by default" do
|
135
163
|
expect(@ru.localize(Time.at(0).utc)).to eq('01.01.1970 00:00')
|
136
164
|
end
|
data/spec/r18n_spec.rb
CHANGED
@@ -125,7 +125,7 @@ describe R18n do
|
|
125
125
|
it "has l and t methods" do
|
126
126
|
R18n.set('en')
|
127
127
|
expect(t.yes).to eq('Yes')
|
128
|
-
expect(l(Time.at(0).utc)).to eq('01
|
128
|
+
expect(l(Time.at(0).utc)).to eq('1970-01-01 00:00')
|
129
129
|
end
|
130
130
|
|
131
131
|
it "has helpers mixin" do
|
@@ -135,7 +135,7 @@ describe R18n do
|
|
135
135
|
expect(r18n).to eq(obj)
|
136
136
|
expect(i18n).to eq(obj)
|
137
137
|
expect(t.yes).to eq('Yes')
|
138
|
-
expect(l(Time.at(0).utc)).to eq('01
|
138
|
+
expect(l(Time.at(0).utc)).to eq('1970-01-01 00:00')
|
139
139
|
end
|
140
140
|
|
141
141
|
it "returns available translations" do
|
data/spec/translation_spec.rb
CHANGED
@@ -33,6 +33,15 @@ describe R18n::Translation do
|
|
33
33
|
expect(i18n.one.split.first.to_s).to be_kind_of(String)
|
34
34
|
end
|
35
35
|
|
36
|
+
it "returns strings compatible with activesupport json encoding" do
|
37
|
+
require 'active_support'
|
38
|
+
|
39
|
+
i18n = R18n::I18n.new('en', DIR)
|
40
|
+
json = ActiveSupport::JSON.encode(one: i18n.one)
|
41
|
+
|
42
|
+
expect(json).to eq('{"one":"One"}')
|
43
|
+
end
|
44
|
+
|
36
45
|
it "returns strings by Boolean keys (true, false)" do
|
37
46
|
i18n = R18n::I18n.new('en', DIR)
|
38
47
|
|
@@ -40,7 +49,7 @@ describe R18n::Translation do
|
|
40
49
|
expect(i18n.boolean[false]).to eq('Boolean is false')
|
41
50
|
end
|
42
51
|
|
43
|
-
it "returns html escaped string" do
|
52
|
+
it "returns html escaped string if html_safe is defined" do
|
44
53
|
klass = Class.new(R18n::TranslatedString) do
|
45
54
|
def html_safe
|
46
55
|
'2'
|
@@ -52,6 +61,16 @@ describe R18n::Translation do
|
|
52
61
|
expect(str.html_safe).to eq('2')
|
53
62
|
end
|
54
63
|
|
64
|
+
it "returns unescaped string if html_safe is not defined" do
|
65
|
+
klass = Class.new(R18n::TranslatedString) do
|
66
|
+
undef_method :html_safe if method_defined?(:html_safe)
|
67
|
+
end
|
68
|
+
str = klass.new('a & b', nil, nil)
|
69
|
+
|
70
|
+
expect(str).not_to be_html_safe
|
71
|
+
expect(str.to_s).to eq('a & b')
|
72
|
+
end
|
73
|
+
|
55
74
|
it "loads use hierarchical translations" do
|
56
75
|
i18n = R18n::I18n.new(['ru', 'en'], DIR)
|
57
76
|
expect(i18n.in.another.level).to eq('Иерархический')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
R18n is a i18n tool to translate your Ruby application.
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.5.2
|
176
|
+
rubygems_version: 2.5.2.2
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: I18n tool to translate your Ruby application.
|