relative_time 1.0.0 → 1.1.0

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
- SHA1:
3
- metadata.gz: 7d76ca3fc7d1a64035340910b4f4dad9db9a47dc
4
- data.tar.gz: 4aab3911c7e8582c7542a945a798cc31429dea95
2
+ SHA256:
3
+ metadata.gz: 1bb21472ca972bc14a71e1f9d4fe25285c9b0e301d689eb8f4d84dde5f0a9795
4
+ data.tar.gz: 62cfbb2417caf29323ff4776c64596808503f47e17ff30b4d35af0636d915774
5
5
  SHA512:
6
- metadata.gz: 65a5a3e491107c3e909ab93348a36ed46ef97d5ae06a2a022d31780f98c697c685787fa318e8cf21e5ff3addfc78e81bd175f3a5544880b905081f0b250909a1
7
- data.tar.gz: 7a4270c485735756b2f13cca2912cb86116fab83cccf5e494a2cdfc8ad9d77763976441005c1e5c4a81f5863d3b0f21331c1ce22759ccefb57492dbb0dc74c1d
6
+ metadata.gz: b22ba084d8417c6a2d992c8bb50ab5662295172d4f81efaab13d287c92820a6ddd60d7432abf346e60a0f41b2a1ce6c6b4a12bb1514ddacfbe07738eecce0053
7
+ data.tar.gz: 066f206550011f7b4f77873b252784918df9ef4557a2f288ac610760d27f64ee70d72cd20ee529503bb13f7fc57fec532deac66e0e1a6cf7de9492d4115e962b
@@ -1,8 +1,11 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.0
7
4
  - 2.3.0
5
+ - 2.4.0
6
+ - 2.5.0
7
+ - 2.6.0
8
8
  before_install: gem install bundler -v 1.13.7
9
+ addons:
10
+ code_climate:
11
+ repo_token: be4f42e2cf6fb22ecf1028df50d055d41dc446b31b6b4f96c71fbe7d7ddff48c
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in relative_time.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "simplecov"
8
+ gem "codeclimate-test-reporter", "~> 1.0.0"
9
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # RelativeTime
2
- [![Build Status](https://travis-ci.org/davydovanton/relative_time.svg?branch=master)](https://travis-ci.org/davydovanton/relative_time)
2
+ [![Build Status](https://travis-ci.org/davydovanton/relative_time.svg?branch=master)](https://travis-ci.org/davydovanton/relative_time) [![Code Climate](https://codeclimate.com/github/davydovanton/relative_time/badges/gpa.svg)](https://codeclimate.com/github/davydovanton/relative_time) [![Test Coverage](https://codeclimate.com/github/davydovanton/relative_time/badges/coverage.svg)](https://codeclimate.com/github/davydovanton/relative_time/coverage)
3
3
 
4
- Micro lib without any dependensy for getting relative time.
4
+ Micro lib without any dependency for getting relative time.
5
5
 
6
6
 
7
7
  ## Motivation
@@ -40,7 +40,7 @@ Also you can use second argument as a from date:
40
40
 
41
41
  ```ruby
42
42
  date_from = Time.now - 60 * 60 # one hour ago
43
- RelativeTime.in_words(Time.now, date_from) # => a hour ago
43
+ RelativeTime.in_words(Time.now, date_from) # => an hour ago
44
44
  ```
45
45
 
46
46
  ### Supported intervals
@@ -52,9 +52,26 @@ RelativeTime.in_words(Time.now, date_from) # => a hour ago
52
52
  * months
53
53
  * years
54
54
 
55
+ ### I18n
56
+ Relative time use [i18n](https://github.com/ruby-i18n/i18n) for pluralization and translation to other languages. For using specific locale just call `#in_words` with specific locale:
57
+
58
+ ```ruby
59
+ RelativeTime.in_words(Time.now, locale: :ru) # => через 3 часа
60
+ RelativeTime.in_words(Time.now, date_from, locale: :ru) # => минуту назад
61
+ ```
62
+
63
+ List of supported locales:
64
+
65
+ * `en`
66
+ * `id`
67
+ * `ru`
68
+ * `tr`
69
+ * `uk`
70
+ * `be`
71
+ * `pt`
72
+
55
73
  ## Contributing
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/relative_time. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/davydovanton/relative_time. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
75
 
58
76
  ## License
59
77
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
-
@@ -0,0 +1,37 @@
1
+ be:
2
+ relative:
3
+ less_than_a_minute: 'менш хвіліны таму'
4
+
5
+ ago: '%{date_string} таму'
6
+ in: 'праз %{date_string}'
7
+
8
+ years:
9
+ one: 'год'
10
+ few: '%{count} года'
11
+ many: '%{count} гадоў'
12
+ other: '%{count} гадоў'
13
+ months:
14
+ one: 'месяц'
15
+ few: '%{count} месяцы'
16
+ many: '%{count} месяцаў'
17
+ other: '%{count} месяцаў'
18
+ weeks:
19
+ one: 'тыдзень'
20
+ few: '%{count} тыдні'
21
+ many: '%{count} тыдняў'
22
+ other: '%{count} тыдняў'
23
+ days:
24
+ one: 'дзень'
25
+ few: '%{count} дні'
26
+ many: '%{count} дзён'
27
+ other: '%{count} дзён'
28
+ hours:
29
+ one: 'гадзіну'
30
+ few: '%{count} гадзіны'
31
+ many: '%{count} гадзін'
32
+ other: '%{count} гадзін'
33
+ minutes:
34
+ one: 'хвіліну'
35
+ few: '%{count} хвіліны'
36
+ many: '%{count} хвілін'
37
+ other: '%{count} хвілін'
@@ -0,0 +1,25 @@
1
+ en:
2
+ relative:
3
+ less_than_a_minute: 'less than a minute'
4
+
5
+ ago: '%{date_string} ago'
6
+ in: 'in %{date_string}'
7
+
8
+ years:
9
+ one: 'a year'
10
+ other: '%{count} years'
11
+ months:
12
+ one: 'a month'
13
+ other: '%{count} months'
14
+ weeks:
15
+ one: 'a week'
16
+ other: '%{count} weeks'
17
+ days:
18
+ one: 'a day'
19
+ other: '%{count} days'
20
+ hours:
21
+ one: 'an hour'
22
+ other: '%{count} hours'
23
+ minutes:
24
+ one: 'a minute'
25
+ other: '%{count} minutes'
@@ -0,0 +1,26 @@
1
+ id:
2
+ relative:
3
+ less_than_a_minute: 'kurang dari 1 menit'
4
+
5
+ ago: '%{date_string} yang lalu'
6
+ in: 'dalam %{date_string}'
7
+
8
+ years:
9
+ one: 'setahun'
10
+ other: '%{count} tahun'
11
+ months:
12
+ one: 'sebulan'
13
+ other: '%{count} bulan'
14
+ weeks:
15
+ one: 'seminggu'
16
+ other: '%{count} minggu'
17
+ days:
18
+ one: 'sehari'
19
+ other: '%{count} hari'
20
+ hours:
21
+ one: 'sejam'
22
+ other: '%{count} jam'
23
+ minutes:
24
+ one: 'semenit'
25
+ other: '%{count} menit'
26
+
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ {
4
+ af: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
5
+ am: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
6
+ ar: { i18n: { plural: { keys: [:zero, :one, :two, :few, :many, :other], rule: lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : [3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99].include?(n % 100) ? :many : :other } } } },
7
+ az: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
8
+ be: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
9
+ bg: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
10
+ bh: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
11
+ bn: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
12
+ bo: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
13
+ bs: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
14
+ ca: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
15
+ cs: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
16
+ cy: { i18n: { plural: { keys: [:one, :two, :many, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } },
17
+ da: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
18
+ de: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
19
+ dz: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
20
+ el: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
21
+ en: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
22
+ eo: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
23
+ es: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
24
+ et: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
25
+ eu: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
26
+ fa: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
27
+ fi: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
28
+ fil: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
29
+ fo: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
30
+ fr: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n.between?(0, 2) && n != 2 ? :one : :other } } } },
31
+ fur: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
32
+ fy: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
33
+ ga: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
34
+ gl: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
35
+ gu: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
36
+ guw: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
37
+ ha: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
38
+ he: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
39
+ hi: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
40
+ hr: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
41
+ hu: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
42
+ id: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
43
+ is: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
44
+ it: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
45
+ iw: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
46
+ ja: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
47
+ jv: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
48
+ ka: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
49
+ km: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
50
+ kn: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
51
+ ko: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
52
+ ku: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
53
+ lb: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
54
+ ln: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
55
+ lt: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n % 10 == 1 && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :one : [2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :few : :other } } } },
56
+ lv: { i18n: { plural: { keys: [:zero, :one, :other], rule: lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } } },
57
+ mg: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
58
+ mk: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n % 10 == 1 ? :one : :other } } } },
59
+ ml: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
60
+ mn: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
61
+ mo: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
62
+ mr: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
63
+ ms: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
64
+ mt: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n == 1 ? :one : n == 0 || [2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :many : :other } } } },
65
+ my: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
66
+ nah: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
67
+ nb: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
68
+ ne: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
69
+ nl: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
70
+ nn: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
71
+ no: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
72
+ nso: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
73
+ oc: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
74
+ om: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
75
+ or: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
76
+ pa: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
77
+ pap: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
78
+ pl: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : (n != 1 && [0, 1].include?(n % 10)) || [5, 6, 7, 8, 9].include?(n % 10) || [12, 13, 14].include?(n % 100) ? :many : :other } } } },
79
+ ps: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
80
+ pt: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
81
+ "pt-PT": { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
82
+ ro: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
83
+ ru: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
84
+ se: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
85
+ sh: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
86
+ sk: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
87
+ sl: { i18n: { plural: { keys: [:one, :two, :few, :other], rule: lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } },
88
+ sma: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
89
+ smi: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
90
+ smj: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
91
+ smn: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
92
+ sms: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
93
+ so: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
94
+ sq: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
95
+ sr: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
96
+ sv: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
97
+ sw: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
98
+ ta: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
99
+ te: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
100
+ th: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
101
+ ti: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
102
+ tk: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
103
+ tl: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
104
+ to: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
105
+ tr: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
106
+ uk: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
107
+ ur: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } },
108
+ vi: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
109
+ wa: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
110
+ yo: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
111
+ zh: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } },
112
+ au: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }
113
+ }
@@ -0,0 +1,25 @@
1
+ pt:
2
+ relative:
3
+ less_than_a_minute: 'menos de um minuto'
4
+
5
+ ago: 'há %{date_string}'
6
+ in: 'em %{date_string}'
7
+
8
+ years:
9
+ one: 'um ano'
10
+ other: '%{count} anos'
11
+ months:
12
+ one: 'um mês'
13
+ other: '%{count} meses'
14
+ weeks:
15
+ one: 'uma semana'
16
+ other: '%{count} semanas'
17
+ days:
18
+ one: 'um dia'
19
+ other: '%{count} dias'
20
+ hours:
21
+ one: 'uma hora'
22
+ other: '%{count} horas'
23
+ minutes:
24
+ one: 'um minuto'
25
+ other: '%{count} minutos'
@@ -0,0 +1,37 @@
1
+ ru:
2
+ relative:
3
+ less_than_a_minute: 'меньше минуты назад'
4
+
5
+ ago: '%{date_string} назад'
6
+ in: 'через %{date_string}'
7
+
8
+ years:
9
+ one: 'год'
10
+ few: '%{count} года'
11
+ many: '%{count} лет'
12
+ other: '%{count} лет'
13
+ months:
14
+ one: 'месяц'
15
+ few: '%{count} месяца'
16
+ many: '%{count} месяцев'
17
+ other: '%{count} месяцев'
18
+ weeks:
19
+ one: 'неделю'
20
+ few: '%{count} недели'
21
+ many: '%{count} недель'
22
+ other: '%{count} недель'
23
+ days:
24
+ one: 'день'
25
+ few: '%{count} дня'
26
+ many: '%{count} дней'
27
+ other: '%{count} дней'
28
+ hours:
29
+ one: 'час'
30
+ few: '%{count} часа'
31
+ many: '%{count} часов'
32
+ other: '%{count} часов'
33
+ minutes:
34
+ one: 'минуту'
35
+ few: '%{count} минуты'
36
+ many: '%{count} минут'
37
+ other: '%{count} минут'
@@ -0,0 +1,19 @@
1
+ tr:
2
+ relative:
3
+ less_than_a_minute: '1 dakikadan daha az'
4
+
5
+ ago: '%{date_string} önce'
6
+ in: '%{date_string} içinde'
7
+
8
+ years:
9
+ other: '%{count} yıl'
10
+ months:
11
+ other: '%{count} ay'
12
+ weeks:
13
+ other: '%{count} hafta'
14
+ days:
15
+ other: '%{count} gün'
16
+ hours:
17
+ other: '%{count} saat'
18
+ minutes:
19
+ other: '%{count} dakika'
@@ -0,0 +1,37 @@
1
+ uk:
2
+ relative:
3
+ less_than_a_minute: 'менш ніж хвилину тому'
4
+
5
+ ago: '%{date_string} тому'
6
+ in: 'за %{date_string}'
7
+
8
+ years:
9
+ one: 'рік'
10
+ few: '%{count} роки'
11
+ many: '%{count} років'
12
+ other: '%{count} років'
13
+ months:
14
+ one: 'місяць'
15
+ few: '%{count} місяці'
16
+ many: '%{count} місяців'
17
+ other: '%{count} місяців'
18
+ weeks:
19
+ one: 'тиждень'
20
+ few: '%{count} тижні'
21
+ many: '%{count} тижнів'
22
+ other: '%{count} тижнів'
23
+ days:
24
+ one: 'день'
25
+ few: '%{count} дні'
26
+ many: '%{count} днів'
27
+ other: '%{count} днів'
28
+ hours:
29
+ one: 'година'
30
+ few: '%{count} години'
31
+ many: '%{count} годин'
32
+ other: '%{count} годин'
33
+ minutes:
34
+ one: 'хвилина'
35
+ few: '%{count} хвилини'
36
+ many: '%{count} хвилин'
37
+ other: '%{count} хвилин'
@@ -2,8 +2,7 @@ require 'relative_time/in_words'
2
2
  require 'relative_time/version'
3
3
 
4
4
  module RelativeTime
5
- # Your code goes here...
6
- def self.in_words(date_to, date_from = Time.now)
7
- InWords.new.(date_to, date_from)
5
+ def self.in_words(date_to, date_from = Time.now, locale: :en)
6
+ InWords.new(locale: locale).(date_to, date_from)
8
7
  end
9
8
  end
@@ -1,42 +1,53 @@
1
+ require 'i18n'
2
+ require 'i18n/backend/pluralization'
3
+
1
4
  module RelativeTime
2
5
  class InWords
6
+ def self.setup
7
+ return if @setup
8
+
9
+ I18n.load_path << Dir[File.expand_path("#{__dir__}/../../config/locales") + '/*.yml']
10
+ I18n.load_path << Dir[File.expand_path("#{__dir__}/../../config/locales") + '/*.rb']
11
+ I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
12
+
13
+ @setup = true
14
+ end
15
+
16
+ def initialize(locale: :en)
17
+ self.class.setup
18
+ I18n.locale = locale
19
+ end
20
+
3
21
  def call(date_to, date_from)
4
- diff = date_from - date_to.to_time
5
- return 'less than a minute' if diff.abs.round <= 59
22
+ diff = date_from.to_time - date_to.to_time
23
+ return I18n.t('relative.less_than_a_minute') if diff.abs.round <= 59
6
24
 
7
- date_string = verb_agreement(resolution(diff.abs.round))
8
- diff >= 0 ? "#{date_string} ago" : "in #{date_string}"
25
+ date_string = resolution(diff.abs.round)
26
+ diff >= 0 ? I18n.t('relative.ago', date_string: date_string) : I18n.t('relative.in', date_string: date_string)
9
27
  end
10
28
 
11
- private
12
- MINUTE = 60
13
- HOUR = 60 * MINUTE
14
- DAY = 24 * HOUR
15
- WEEK = 7 * DAY
16
- MONTH = 4 * WEEK
17
- YEAR = 12 * MONTH
29
+ private
30
+
31
+ MINUTE = 60
32
+ HOUR = 60 * MINUTE
33
+ DAY = 24 * HOUR
34
+ WEEK = 7 * DAY
35
+ MONTH = 4 * WEEK
36
+ YEAR = 12 * MONTH
18
37
 
19
38
  def resolution(diff)
20
39
  if diff >= YEAR
21
- [(diff / YEAR).round, 'years']
40
+ I18n.t('relative.years', count: (diff / YEAR).round)
22
41
  elsif diff >= MONTH
23
- [(diff / MONTH).round, 'months']
42
+ I18n.t('relative.months', count: (diff / MONTH).round)
24
43
  elsif diff >= WEEK
25
- [(diff / WEEK).round, 'weeks']
44
+ I18n.t('relative.weeks', count: (diff / WEEK).round)
26
45
  elsif diff >= DAY
27
- [(diff / DAY).round, 'days']
46
+ I18n.t('relative.days', count: (diff / DAY).round)
28
47
  elsif diff >= HOUR
29
- [(diff / HOUR).round, 'hours']
30
- else
31
- [(diff / MINUTE).round, 'minutes']
32
- end
33
- end
34
-
35
- def verb_agreement(resolution)
36
- if resolution[0] == 1
37
- "a #{resolution.last[0...-1]}"
48
+ I18n.t('relative.hours', count: (diff / HOUR).round)
38
49
  else
39
- resolution.join(' ')
50
+ I18n.t('relative.minutes', count: (diff / MINUTE).round)
40
51
  end
41
52
  end
42
53
  end
@@ -1,3 +1,3 @@
1
1
  module RelativeTime
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Anton Davydov"]
10
10
  spec.email = ["antondavydov.o@gmail.com"]
11
11
 
12
- spec.summary = %q{Micro lib without any dependensy for getting relative time}
13
- spec.description = %q{Micro lib without any dependensy for getting relative time}
12
+ spec.summary = %q{Micro lib without any dependency for getting relative time}
13
+ spec.description = %q{Micro lib without any dependency for getting relative time}
14
14
  spec.homepage = "https://github.com/davydovanton/relative_time"
15
15
  spec.license = "MIT"
16
16
 
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
+ spec.add_dependency "i18n"
26
+
25
27
  spec.add_development_dependency "bundler", "~> 1.13"
26
28
  spec.add_development_dependency "rake", "~> 10.0"
27
29
  spec.add_development_dependency "minitest", "~> 5.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relative_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Davydov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +66,7 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '5.0'
55
- description: Micro lib without any dependensy for getting relative time
69
+ description: Micro lib without any dependency for getting relative time
56
70
  email:
57
71
  - antondavydov.o@gmail.com
58
72
  executables: []
@@ -66,6 +80,14 @@ files:
66
80
  - LICENSE.txt
67
81
  - README.md
68
82
  - Rakefile
83
+ - config/locales/be.yml
84
+ - config/locales/en.yml
85
+ - config/locales/id.yml
86
+ - config/locales/plurals.rb
87
+ - config/locales/pt.yml
88
+ - config/locales/ru.yml
89
+ - config/locales/tr.yml
90
+ - config/locales/uk.yml
69
91
  - lib/relative_time.rb
70
92
  - lib/relative_time/in_words.rb
71
93
  - lib/relative_time/version.rb
@@ -90,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
112
  version: '0'
91
113
  requirements: []
92
114
  rubyforge_project:
93
- rubygems_version: 2.5.1
115
+ rubygems_version: 2.7.3
94
116
  signing_key:
95
117
  specification_version: 4
96
- summary: Micro lib without any dependensy for getting relative time
118
+ summary: Micro lib without any dependency for getting relative time
97
119
  test_files: []