rails-timeago 1.4.3 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -39
- data/lib/assets/javascripts/rails-timeago-all.js +38 -0
- data/lib/rails-timeago.rb +0 -93
- data/lib/rails-timeago/helper.rb +3 -13
- data/lib/rails-timeago/version.rb +4 -4
- data/rails-timeago.gemspec +1 -1
- data/spec/support/stub.rb +2 -2
- data/spec/timeago/helper_spec.rb +2 -69
- data/vendor/assets/javascripts/jquery.timeago.js +10 -9
- data/vendor/assets/javascripts/locales/jquery.timeago.ar.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.bg.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.bs.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.ca.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.cy.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.cz.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.da.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.de.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.el.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.en-short.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.es.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.fa.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.fi.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.fr.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.he.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.hr.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.hu.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.hy.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.id.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.it.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.ja.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.ko.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.mk.js +20 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.nl.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.no.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.pl.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.pt-br.js +16 -0
- data/vendor/assets/javascripts/locales/jquery.timeago.pt.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.ro.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.ru.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.sv.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.tr.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.uk.js +2 -2
- data/vendor/assets/javascripts/locales/jquery.timeago.uz.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.zh-CN.js +1 -1
- data/vendor/assets/javascripts/locales/jquery.timeago.zh-TW.js +1 -1
- metadata +8 -6
- data/spec/timeago_spec.rb +0 -66
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'rails-timeago'
|
11
|
+
gem 'rails-timeago', '~> 2.0.0.beta1'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -25,6 +25,10 @@ To use bundled jQuery Timeago plugin add this require statement to your applicat
|
|
25
25
|
|
26
26
|
This will also convert all matching time tags on page load.
|
27
27
|
|
28
|
+
Use the following to also include all available locale files:
|
29
|
+
|
30
|
+
//= require rails-timeago-all
|
31
|
+
|
28
32
|
## Usage
|
29
33
|
|
30
34
|
Use the timeago_tag helper like any other regular tag helper:
|
@@ -60,7 +64,6 @@ Force time ago tag ignoring limit option.
|
|
60
64
|
String that will be returned if time is nil.
|
61
65
|
(default: '-')
|
62
66
|
|
63
|
-
|
64
67
|
All other options will be given as options to the time tag helper.
|
65
68
|
The above options can be assigned globally as defaults using
|
66
69
|
|
@@ -68,60 +71,42 @@ The above options can be assigned globally as defaults using
|
|
68
71
|
Rails::Timeago.default_options :limit => proc { 20.days.ago }, :nojs => true
|
69
72
|
```
|
70
73
|
|
71
|
-
A global limit should always be given as a block that will be evaluated each time
|
72
|
-
the rails timeago_tag helper is called. That avoids the limit becoming smaller the
|
73
|
-
longer the application runs.
|
74
|
+
A global limit should always be given as a block that will be evaluated each time the rails timeago_tag helper is called. That avoids the limit becoming smaller the longer the application runs.
|
74
75
|
|
75
76
|
## I18n
|
76
77
|
|
77
|
-
**rails-timeago**
|
78
|
-
files for the following locales taken from [jQuery Timeago](https://github.com/rmm5t/jquery-timeago).
|
78
|
+
**rails-timeago 2** ships with a modified version of jQuery timeago that allows to include all locale files at once and set the locale via an option or per element via the `lang` attribute:
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
```erb
|
81
|
+
<%= timeago_tag Time.zone.now, :lang => :de %>
|
82
|
+
```
|
83
83
|
|
84
|
-
|
85
|
-
locale if it is available. You only have to include the following method into
|
86
|
-
your html head tag:
|
84
|
+
The following snippet will print a script tag that set the jQuery timeago locale according to your `I18n.locale`:
|
87
85
|
|
88
86
|
```ruby
|
89
87
|
<%= timeago_script_tag %>
|
90
88
|
```
|
91
89
|
|
92
|
-
|
93
|
-
**rails-timeago** will also add all locale files to Rails precompiled assets
|
94
|
-
list to allow precompilation. By default all locale files will be included but
|
95
|
-
you can specify a list by adding a initializer similar to:
|
90
|
+
Just insert it in your application layout's html head. If you use another I18n framework for JavaScript you can also directly set `jQuery.timeago.settings.lang`.
|
96
91
|
|
97
|
-
|
98
|
-
Rails::Timeago.locales = [:en, :de, "zh-CN", :sjn]
|
99
|
-
```
|
92
|
+
Do not forget to require the needed locale files by either require `rails-timeago-all` in your `application.js` file or require specific locale files:
|
100
93
|
|
101
|
-
|
102
|
-
|
103
|
-
locale file lookup for `timeago_script_tag`.
|
104
|
-
To add your own locales add a file in JavaScript assets directory named
|
105
|
-
`locales/jquery.timeago.<locale>.js` and add your locale to `Rails::Timeago.locales`.
|
94
|
+
//= require locales/jquery.timeago.de.js
|
95
|
+
//= require locales/jquery.timeago.ru.js
|
106
96
|
|
107
|
-
|
108
|
-
especially useful to override the embedded `en` locale because there is no English
|
109
|
-
locale file that can be overridden:
|
97
|
+
*Note:* English is included in jQuery timeago library, but can be easily override by include an own file that defines `jQuery.timeago.settings.strings["en"]`. See a locale file for more details.
|
110
98
|
|
111
|
-
|
112
|
-
Rails::Timeago.map_locale "en", "better/locales/en.js"
|
113
|
-
```
|
99
|
+
**rails-timeago** includes locale files for the following locales taken from [jQuery Timeago](https://github.com/rmm5t/jquery-timeago).
|
114
100
|
|
115
|
-
|
116
|
-
|
101
|
+
> ar, bg, bs, ca, cy, cz, da, de, el, en, en-short, es, fa, fi, fr,
|
102
|
+
> he, hr, hu, hy, id, it, ja, ko, mk, nl, no, pl, pt, pt-br, ro, ru,
|
103
|
+
> sv, tr, uk, uz, zh-CN, zh-TW
|
117
104
|
|
118
|
-
**
|
119
|
-
in your assets directory. That will also include all your custom locale files if you
|
120
|
-
place them in `app/assets/javascripts/locales` and will result in unexpected behavior when
|
121
|
-
using `en` locale (see #5).
|
105
|
+
Your customized jQuery locale files must be changed to work with **rails-timeago 2**. Instead of defining your locale strings as `jQuery.timeago.settings.strings` you need to define them like this:
|
122
106
|
|
123
|
-
|
124
|
-
|
107
|
+
jQuery.timeago.settings.string["en"] = {
|
108
|
+
...
|
109
|
+
}
|
125
110
|
|
126
111
|
## License
|
127
112
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// Rails timeago bootstrap with all locales
|
2
|
+
//= require rails-timeago
|
3
|
+
//= require locales/jquery.timeago.de.js
|
4
|
+
//= require locales/jquery.timeago.cy.js
|
5
|
+
//= require locales/jquery.timeago.pl.js
|
6
|
+
//= require locales/jquery.timeago.mk.js
|
7
|
+
//= require locales/jquery.timeago.zh-CN.js
|
8
|
+
//= require locales/jquery.timeago.bs.js
|
9
|
+
//= require locales/jquery.timeago.en-short.js
|
10
|
+
//= require locales/jquery.timeago.it.js
|
11
|
+
//= require locales/jquery.timeago.fi.js
|
12
|
+
//= require locales/jquery.timeago.es.js
|
13
|
+
//= require locales/jquery.timeago.uk.js
|
14
|
+
//= require locales/jquery.timeago.zh-TW.js
|
15
|
+
//= require locales/jquery.timeago.hy.js
|
16
|
+
//= require locales/jquery.timeago.ca.js
|
17
|
+
//= require locales/jquery.timeago.pt.js
|
18
|
+
//= require locales/jquery.timeago.el.js
|
19
|
+
//= require locales/jquery.timeago.sv.js
|
20
|
+
//= require locales/jquery.timeago.ar.js
|
21
|
+
//= require locales/jquery.timeago.no.js
|
22
|
+
//= require locales/jquery.timeago.fa.js
|
23
|
+
//= require locales/jquery.timeago.fr.js
|
24
|
+
//= require locales/jquery.timeago.pt-br.js
|
25
|
+
//= require locales/jquery.timeago.tr.js
|
26
|
+
//= require locales/jquery.timeago.he.js
|
27
|
+
//= require locales/jquery.timeago.bg.js
|
28
|
+
//= require locales/jquery.timeago.ko.js
|
29
|
+
//= require locales/jquery.timeago.uz.js
|
30
|
+
//= require locales/jquery.timeago.cz.js
|
31
|
+
//= require locales/jquery.timeago.hu.js
|
32
|
+
//= require locales/jquery.timeago.id.js
|
33
|
+
//= require locales/jquery.timeago.hr.js
|
34
|
+
//= require locales/jquery.timeago.ru.js
|
35
|
+
//= require locales/jquery.timeago.nl.js
|
36
|
+
//= require locales/jquery.timeago.da.js
|
37
|
+
//= require locales/jquery.timeago.ja.js
|
38
|
+
//= require locales/jquery.timeago.ro.js
|
data/lib/rails-timeago.rb
CHANGED
@@ -13,27 +13,6 @@ module Rails
|
|
13
13
|
ActiveSupport.on_load(:action_view) do
|
14
14
|
include Rails::Timeago::Helper
|
15
15
|
end
|
16
|
-
|
17
|
-
if app.config.assets.locales
|
18
|
-
app.config.assets.precompile +=
|
19
|
-
app.config.assets.locales.map do |locale|
|
20
|
-
if ::Rails::Timeago.has_locale_file locale
|
21
|
-
'locales/jquery.timeago.' + locale.to_s + '.js'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
elsif ::Rails::Timeago.locales.empty?
|
25
|
-
app.config.assets.precompile +=
|
26
|
-
Dir[Rails::Timeago.locale_path + '*.js'].map do |f|
|
27
|
-
'locales/' + File.basename(f)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
app.config.assets.precompile +=
|
31
|
-
::Rails::Timeago.locales.map do |locale|
|
32
|
-
if ::Rails::Timeago.has_locale_file locale
|
33
|
-
'locales/jquery.timeago.' + locale.to_s + '.js'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
16
|
end
|
38
17
|
end
|
39
18
|
end
|
@@ -82,77 +61,5 @@ module Rails
|
|
82
61
|
@defaults
|
83
62
|
end
|
84
63
|
end
|
85
|
-
|
86
|
-
# Allow to map a locale to a specific url. May be useful for
|
87
|
-
# overriding embedded english locale:
|
88
|
-
#
|
89
|
-
# Rails::Timeago.map_locale :en, "better/locales/en.js"
|
90
|
-
#
|
91
|
-
def self.map_locale(locale, url)
|
92
|
-
@locale_map ||= {}
|
93
|
-
@locale_map[locale.to_s] = url
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.mapped_locale(locale)
|
97
|
-
@locale_map ||= {}
|
98
|
-
@locale_map[locale.to_s]
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.locale_path
|
102
|
-
File.dirname(__FILE__) + '/../vendor/assets/javascripts/locales/'
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.locale_file(locale)
|
106
|
-
locale_path + locale_file_name(locale)
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.locale_file_name(locale)
|
110
|
-
'jquery.timeago.' + locale + '.js'
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.has_locale_file(locale)
|
114
|
-
File.exist? locale_file(locale)
|
115
|
-
end
|
116
|
-
|
117
|
-
# Look up a timeago locale. If no locale is given I18n's
|
118
|
-
# default locale will be used. Lookup follows the given
|
119
|
-
# order:
|
120
|
-
# 1) ll-CC (language and country)
|
121
|
-
# 2) ll (only language)
|
122
|
-
# 3) I18n default locale
|
123
|
-
# 4) "en"
|
124
|
-
def self.lookup_locale(locale = nil)
|
125
|
-
locale = I18n.locale.to_s unless locale
|
126
|
-
|
127
|
-
if locale =~ /^(\w+)(\-(\w+))?$/
|
128
|
-
lang = $1.downcase
|
129
|
-
if $3
|
130
|
-
ctry = $3.upcase
|
131
|
-
return "#{lang}-#{ctry}" if has_locale "#{lang}-#{ctry}"
|
132
|
-
end
|
133
|
-
return lang if has_locale lang
|
134
|
-
end
|
135
|
-
|
136
|
-
return I18n.default_locale.to_s if has_locale I18n.default_locale.to_s
|
137
|
-
"en"
|
138
|
-
end
|
139
|
-
|
140
|
-
def self.has_locale(locale)
|
141
|
-
return locales.include? locale if locales.any?
|
142
|
-
return true if @locale_map and @locale_map[locale.to_s]
|
143
|
-
return has_locale_file locale
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.locales
|
147
|
-
@locales ||= []
|
148
|
-
end
|
149
|
-
|
150
|
-
def self.locales=(*attrs)
|
151
|
-
if attrs[0].kind_of?(Array)
|
152
|
-
@locales = attrs[0].map(&:to_s)
|
153
|
-
else
|
154
|
-
@locales = attrs.map(&:to_s)
|
155
|
-
end
|
156
|
-
end
|
157
64
|
end
|
158
65
|
end
|
data/lib/rails-timeago/helper.rb
CHANGED
@@ -55,19 +55,9 @@ module Rails
|
|
55
55
|
I18n.l time, :format => time_options[:format]
|
56
56
|
end
|
57
57
|
|
58
|
-
# Return a JavaScript tag to
|
59
|
-
|
60
|
-
|
61
|
-
locale = ::Rails::Timeago.lookup_locale locale
|
62
|
-
|
63
|
-
file = ::Rails::Timeago.mapped_locale locale
|
64
|
-
return javascript_include_tag file if file
|
65
|
-
|
66
|
-
if locale != 'en'
|
67
|
-
javascript_include_tag 'locales/' + ::Rails::Timeago.locale_file_name(locale)
|
68
|
-
else
|
69
|
-
'' # English locale is embedded in jQuery timeago plugin file.
|
70
|
-
end
|
58
|
+
# Return a JavaScript tag to set jQuery timeago locale.
|
59
|
+
def timeago_script_tag
|
60
|
+
javascript_tag "jQuery.timeago.settings.lang=\"#{I18n.locale}\";" if I18n.locale != 'en'
|
71
61
|
end
|
72
62
|
end
|
73
63
|
end
|
data/rails-timeago.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.homepage = "https://github.com/jgraichen/rails-timeago"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
-
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.files = `git ls-files`.split("\n").reject{|file| file =~ /^scripts/}
|
13
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
gem.name = "rails-timeago"
|
15
15
|
gem.require_paths = ["lib"]
|
data/spec/support/stub.rb
CHANGED
data/spec/timeago/helper_spec.rb
CHANGED
@@ -87,76 +87,9 @@ describe Rails::Timeago::Helper do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
context "#timeago_script_tag" do
|
90
|
-
it "should
|
91
|
-
Rails::Timeago.map_locale :en, nil
|
90
|
+
it "should return a javascript snippet to set jQuery timeago locale" do
|
92
91
|
I18n.locale = "en"
|
93
|
-
@stub.timeago_script_tag.should == ""
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should return mapped 'en' locale file if mapping exists" do
|
97
|
-
Rails::Timeago.map_locale :en, "better/locale/en.js"
|
98
|
-
|
99
|
-
I18n.locale = "en"
|
100
|
-
@stub.timeago_script_tag.should == '<script src="better/locale/en.js"></script>'
|
101
|
-
|
102
|
-
Rails::Timeago.map_locale :en, nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should return javascript tag with locale file" do
|
106
|
-
I18n.locale = "de"
|
107
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.de.js"></script>'
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should return javascript tag with mapped locale file" do
|
111
|
-
Rails::Timeago.map_locale :de, "deutsch.js"
|
112
|
-
|
113
|
-
I18n.locale = "de"
|
114
|
-
@stub.timeago_script_tag.should == '<script src="deutsch.js"></script>'
|
115
|
-
|
116
|
-
Rails::Timeago.map_locale :de, nil
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should return javascript tag with full locale file if available" do
|
120
|
-
I18n.locale = "zh-CN"
|
121
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.zh-CN.js"></script>'
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should return javascript tag with lang locale file if available" do
|
125
|
-
I18n.locale = "nl-NL"
|
126
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.nl.js"></script>'
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should return javascript tag with formatted locale file" do
|
130
|
-
I18n.locale = "zh-cn"
|
131
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.zh-CN.js"></script>'
|
132
|
-
end
|
133
|
-
|
134
|
-
context "with global locale configuration" do
|
135
|
-
before { Rails::Timeago.locales = [:de, :en, "zh-CN", "tlh", "nl"] }
|
136
|
-
after { Rails::Timeago.locales = [] }
|
137
|
-
|
138
|
-
it "should include full locale if available" do
|
139
|
-
I18n.locale = "zh-CN"
|
140
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.zh-CN.js"></script>'
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should include lang locale if available" do
|
144
|
-
I18n.locale = "nl-NL"
|
145
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.nl.js"></script>'
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should include default locale for not specified locales" do
|
149
|
-
I18n.locale = :ar
|
150
|
-
I18n.default_locale = :de
|
151
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.de.js"></script>'
|
152
|
-
|
153
|
-
I18n.default_locale = :en
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should find added locales that does not have a locale file in gem" do
|
157
|
-
I18n.locale = "tlh"
|
158
|
-
@stub.timeago_script_tag.should == '<script src="locales/jquery.timeago.tlh.js"></script>'
|
159
|
-
end
|
92
|
+
@stub.timeago_script_tag.should == '<script>jQuery.timeago.settings.lang="en";</script>'
|
160
93
|
end
|
161
94
|
end
|
162
95
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
4
4
|
*
|
5
5
|
* @name timeago
|
6
|
-
* @version 0.11.
|
6
|
+
* @version 0.11.4
|
7
7
|
* @requires jQuery v1.2.3+
|
8
8
|
* @author Ryan McGeary
|
9
9
|
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
@@ -31,7 +31,8 @@
|
|
31
31
|
settings: {
|
32
32
|
refreshMillis: 60000,
|
33
33
|
allowFuture: false,
|
34
|
-
|
34
|
+
lang: "en",
|
35
|
+
strings: { "en": {
|
35
36
|
prefixAgo: null,
|
36
37
|
prefixFromNow: null,
|
37
38
|
suffixAgo: "ago",
|
@@ -49,10 +50,10 @@
|
|
49
50
|
years: "%d years",
|
50
51
|
wordSeparator: " ",
|
51
52
|
numbers: []
|
52
|
-
}
|
53
|
+
}}
|
53
54
|
},
|
54
|
-
inWords: function(distanceMillis) {
|
55
|
-
var $l = this.settings.strings;
|
55
|
+
inWords: function(distanceMillis, lang) {
|
56
|
+
var $l = this.settings.strings[lang] || this.settings.strings[this.settings.lang] || this.settings.strings["en"];
|
56
57
|
var prefix = $l.prefixAgo;
|
57
58
|
var suffix = $l.suffixAgo;
|
58
59
|
if (this.settings.allowFuture) {
|
@@ -91,7 +92,7 @@
|
|
91
92
|
},
|
92
93
|
parse: function(iso8601) {
|
93
94
|
var s = $.trim(iso8601);
|
94
|
-
s = s.replace(/\.\d
|
95
|
+
s = s.replace(/\.\d+/,""); // remove milliseconds
|
95
96
|
s = s.replace(/-/,"/").replace(/-/,"/");
|
96
97
|
s = s.replace(/T/," ").replace(/Z/," UTC");
|
97
98
|
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
@@ -121,7 +122,7 @@
|
|
121
122
|
function refresh() {
|
122
123
|
var data = prepareData(this);
|
123
124
|
if (!isNaN(data.datetime)) {
|
124
|
-
$(this).text(inWords(data.datetime));
|
125
|
+
$(this).text(inWords(data.datetime, ($(this).attr('lang')) ? $(this).attr('lang') : $t.settings.lang));
|
125
126
|
}
|
126
127
|
return this;
|
127
128
|
}
|
@@ -138,8 +139,8 @@
|
|
138
139
|
return element.data("timeago");
|
139
140
|
}
|
140
141
|
|
141
|
-
function inWords(date) {
|
142
|
-
return $t.inWords(distance(date));
|
142
|
+
function inWords(date, lang) {
|
143
|
+
return $t.inWords(distance(date), lang);
|
143
144
|
}
|
144
145
|
|
145
146
|
function distance(date) {
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// Macedonian
|
2
|
+
(function() {
|
3
|
+
jQuery.timeago.settings.strings["mk"]={
|
4
|
+
prefixAgo: "пред",
|
5
|
+
prefixFromNow: "за",
|
6
|
+
suffixAgo: null,
|
7
|
+
suffixFromNow: null,
|
8
|
+
seconds: "%d секунди",
|
9
|
+
minute: "%d минута",
|
10
|
+
minutes: "%d минути",
|
11
|
+
hour: "%d час",
|
12
|
+
hours: "%d часа",
|
13
|
+
day: "%d ден",
|
14
|
+
days: "%d денови" ,
|
15
|
+
month: "%d месец",
|
16
|
+
months: "%d месеци",
|
17
|
+
year: "%d година",
|
18
|
+
years: "%d години"
|
19
|
+
}
|
20
|
+
})();
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// Brazilian Portuguese
|
2
|
+
jQuery.timeago.settings.strings["pt-br"] = {
|
3
|
+
suffixAgo: "atrás",
|
4
|
+
suffixFromNow: "nesse momento",
|
5
|
+
seconds: "alguns segundos",
|
6
|
+
minute: "há um minuto",
|
7
|
+
minutes: "há %d minutos",
|
8
|
+
hour: "há uma hora",
|
9
|
+
hours: "há %d horas",
|
10
|
+
day: "há um dia",
|
11
|
+
days: "há %d dias",
|
12
|
+
month: "há um mês",
|
13
|
+
months: "há %d meses",
|
14
|
+
year: "há um ano",
|
15
|
+
years: "há %d anos"
|
16
|
+
};
|
@@ -14,12 +14,12 @@
|
|
14
14
|
}
|
15
15
|
}
|
16
16
|
|
17
|
-
jQuery.timeago.settings.strings = {
|
17
|
+
jQuery.timeago.settings.strings["uk"] = {
|
18
18
|
prefixAgo: null,
|
19
19
|
prefixFromNow: "через",
|
20
20
|
suffixAgo: "тому",
|
21
21
|
suffixFromNow: null,
|
22
|
-
seconds: "
|
22
|
+
seconds: "менше хвилини",
|
23
23
|
minute: "хвилина",
|
24
24
|
minutes: function(value) { return numpf(value, "%d хвилина", "%d хвилини", "%d хвилин"); },
|
25
25
|
hour: "година",
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-timeago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jan Graichen
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- LICENSE
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
74
|
+
- lib/assets/javascripts/rails-timeago-all.js
|
74
75
|
- lib/assets/javascripts/rails-timeago.js
|
75
76
|
- lib/rails-timeago.rb
|
76
77
|
- lib/rails-timeago/helper.rb
|
@@ -79,7 +80,6 @@ files:
|
|
79
80
|
- spec/spec_helper.rb
|
80
81
|
- spec/support/stub.rb
|
81
82
|
- spec/timeago/helper_spec.rb
|
82
|
-
- spec/timeago_spec.rb
|
83
83
|
- vendor/assets/javascripts/jquery.timeago.js
|
84
84
|
- vendor/assets/javascripts/locales/jquery.timeago.ar.js
|
85
85
|
- vendor/assets/javascripts/locales/jquery.timeago.bg.js
|
@@ -103,9 +103,11 @@ files:
|
|
103
103
|
- vendor/assets/javascripts/locales/jquery.timeago.it.js
|
104
104
|
- vendor/assets/javascripts/locales/jquery.timeago.ja.js
|
105
105
|
- vendor/assets/javascripts/locales/jquery.timeago.ko.js
|
106
|
+
- vendor/assets/javascripts/locales/jquery.timeago.mk.js
|
106
107
|
- vendor/assets/javascripts/locales/jquery.timeago.nl.js
|
107
108
|
- vendor/assets/javascripts/locales/jquery.timeago.no.js
|
108
109
|
- vendor/assets/javascripts/locales/jquery.timeago.pl.js
|
110
|
+
- vendor/assets/javascripts/locales/jquery.timeago.pt-br.js
|
109
111
|
- vendor/assets/javascripts/locales/jquery.timeago.pt.js
|
110
112
|
- vendor/assets/javascripts/locales/jquery.timeago.ro.js
|
111
113
|
- vendor/assets/javascripts/locales/jquery.timeago.ru.js
|
@@ -130,9 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
133
|
none: false
|
132
134
|
requirements:
|
133
|
-
- - ! '
|
135
|
+
- - ! '>'
|
134
136
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
137
|
+
version: 1.3.1
|
136
138
|
requirements: []
|
137
139
|
rubyforge_project:
|
138
140
|
rubygems_version: 1.8.24
|
data/spec/timeago_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
|
2
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
-
|
4
|
-
describe Rails::Timeago do
|
5
|
-
context "#lookup_locale" do
|
6
|
-
it "should return full locale if available" do
|
7
|
-
Rails::Timeago.lookup_locale("zh-CN").should == "zh-CN"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should return formatted locale" do
|
11
|
-
Rails::Timeago.lookup_locale("zh-cn").should == "zh-CN"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return lang locale if available" do
|
15
|
-
Rails::Timeago.lookup_locale("nl-NL").should == "nl"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return locale if available" do
|
19
|
-
Rails::Timeago.lookup_locale("de").should == "de"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should lookup default locale if nothing given" do
|
23
|
-
I18n.locale = "ar"
|
24
|
-
|
25
|
-
Rails::Timeago.lookup_locale.should == "ar"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return english locale if locale does not
|
29
|
-
match and default locale is not available" do
|
30
|
-
|
31
|
-
I18n.locale = "sjn"
|
32
|
-
Rails::Timeago.lookup_locale("tlh").should == "en"
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with global locale configuration" do
|
36
|
-
before { Rails::Timeago.locales = [:de, :en, "zh-CN", "tlh"] }
|
37
|
-
after { Rails::Timeago.locales = [] }
|
38
|
-
|
39
|
-
it "should return full locale if available" do
|
40
|
-
Rails::Timeago.lookup_locale("zh-CN").should == "zh-CN"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return lang locale if available" do
|
44
|
-
Rails::Timeago.lookup_locale("en-US").should == "en"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return use default locale if available" do
|
48
|
-
I18n.locale = "en"
|
49
|
-
Rails::Timeago.lookup_locale.should == "en"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return default locale for not specified locales" do
|
53
|
-
I18n.locale = "ar"
|
54
|
-
I18n.default_locale = :de
|
55
|
-
Rails::Timeago.lookup_locale.should == "de"
|
56
|
-
|
57
|
-
I18n.default_locale = :en
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should find added locales that does not have a locale file in gem" do
|
61
|
-
I18n.locale = "tlh"
|
62
|
-
Rails::Timeago.lookup_locale.should == "tlh"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|