i18n-js 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile.lock +19 -17
- data/README.rdoc +12 -11
- data/config/i18n-js.yml +18 -0
- data/i18n-js.gemspec +3 -2
- data/lib/i18n-js.rb +23 -5
- data/lib/i18n-js/engine.rb +7 -0
- data/lib/i18n-js/railtie.rb +7 -1
- data/lib/{tasks/i18n-js_tasks.rake → i18n-js/rake.rb} +1 -1
- data/lib/i18n-js/version.rb +2 -2
- data/spec/i18n_spec.js +147 -138
- data/spec/i18n_spec.rb +42 -1
- data/spec/resources/locales.yml +2 -2
- data/{source → vendor/assets/javascripts}/i18n.js +29 -12
- metadata +87 -75
- data/source/i18n-js.yml +0 -4
data/spec/i18n_spec.rb
CHANGED
@@ -57,9 +57,14 @@ describe SimplesIdeias::I18n do
|
|
57
57
|
SimplesIdeias::I18n.config.should_not be_empty
|
58
58
|
end
|
59
59
|
|
60
|
+
it "sets empty hash as configuration when no file is found" do
|
61
|
+
SimplesIdeias::I18n.config?.should be_false
|
62
|
+
SimplesIdeias::I18n.config.should == {}
|
63
|
+
end
|
64
|
+
|
60
65
|
it "exports messages to default path when configuration file doesn't exist" do
|
61
66
|
SimplesIdeias::I18n.export!
|
62
|
-
|
67
|
+
Rails.root.join(SimplesIdeias::I18n.export_dir, "translations.js").should be_file
|
63
68
|
end
|
64
69
|
|
65
70
|
it "exports messages using the default configuration file" do
|
@@ -154,6 +159,42 @@ describe SimplesIdeias::I18n do
|
|
154
159
|
File.read(SimplesIdeias::I18n.javascript_file).should == "UPDATED"
|
155
160
|
end
|
156
161
|
|
162
|
+
describe "#auto_export?" do
|
163
|
+
it "returns true for development mode" do
|
164
|
+
Rails.env = stub(:development? => true)
|
165
|
+
SimplesIdeias::I18n.should be_auto_export
|
166
|
+
end
|
167
|
+
|
168
|
+
it "returns false for production mode" do
|
169
|
+
Rails.env = stub(:production? => true, :development? => false)
|
170
|
+
SimplesIdeias::I18n.should_not be_auto_export
|
171
|
+
end
|
172
|
+
|
173
|
+
it "returns true for production when configuration is set" do
|
174
|
+
Rails.env = stub(:production? => true, :development? => false)
|
175
|
+
SimplesIdeias::I18n.stub :config? => true, :config => {:auto_export => true}
|
176
|
+
SimplesIdeias::I18n.should be_auto_export
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "#export_dir" do
|
181
|
+
it "detects Rails 3.1" do
|
182
|
+
Rails.version = "3.1"
|
183
|
+
SimplesIdeias::I18n.export_dir == "vendor/assets/javascripts"
|
184
|
+
end
|
185
|
+
|
186
|
+
it "acts as older Rails when asset pipeline is disabled" do
|
187
|
+
Rails.version = "3.1"
|
188
|
+
SimplesIdeias::I18n.stub :config => {:asset_pipeline => false}
|
189
|
+
SimplesIdeias::I18n.export_dir == "public/javascripts"
|
190
|
+
end
|
191
|
+
|
192
|
+
it "detects older Rails" do
|
193
|
+
Rails.version = "3.0.9"
|
194
|
+
SimplesIdeias::I18n.export_dir.to_s.should == "public/javascripts"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
157
198
|
private
|
158
199
|
# Set the configuration as the current one
|
159
200
|
def set_config(path)
|
data/spec/resources/locales.yml
CHANGED
@@ -20,7 +20,7 @@ en:
|
|
20
20
|
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
21
21
|
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
|
22
22
|
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
23
|
-
order: [ :year, :month, :day ]
|
23
|
+
# order: [ :year, :month, :day ]
|
24
24
|
time:
|
25
25
|
formats:
|
26
26
|
default: "%a, %d %b %Y %H:%M:%S %z"
|
@@ -47,7 +47,7 @@ fr:
|
|
47
47
|
abbr_day_names: [dim, lun, mar, mer, jeu, ven, sam]
|
48
48
|
month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre]
|
49
49
|
abbr_month_names: [~, jan., fév., mar., avr., mai, juin, juil., août, sept., oct., nov., déc.]
|
50
|
-
order: [ :day, :month, :year ]
|
50
|
+
# order: [ :day, :month, :year ]
|
51
51
|
time:
|
52
52
|
formats:
|
53
53
|
default: "%d %B %Y %H:%M"
|
@@ -145,12 +145,24 @@ I18n.localize = function(scope, value) {
|
|
145
145
|
}
|
146
146
|
};
|
147
147
|
|
148
|
-
I18n.parseDate = function(
|
149
|
-
var matches,
|
150
|
-
|
148
|
+
I18n.parseDate = function(date) {
|
149
|
+
var matches, convertedDate;
|
150
|
+
|
151
|
+
// we have a date, so just return it.
|
152
|
+
if (typeof(date) == "object") {
|
153
|
+
return date;
|
154
|
+
};
|
155
|
+
|
156
|
+
// it matches the following formats:
|
157
|
+
// yyyy-mm-dd
|
158
|
+
// yyyy-mm-dd[ T]hh:mm::ss
|
159
|
+
// yyyy-mm-dd[ T]hh:mm::ss
|
160
|
+
// yyyy-mm-dd[ T]hh:mm::ssZ
|
161
|
+
// yyyy-mm-dd[ T]hh:mm::ss+0000
|
162
|
+
//
|
163
|
+
matches = date.toString().match(/(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}):(\d{2}))?(Z|\+0000)?/);
|
151
164
|
|
152
165
|
if (matches) {
|
153
|
-
// date/time strings: yyyy-mm-dd hh:mm:ss or yyyy-mm-dd or yyyy-mm-ddThh:mm:ssZ
|
154
166
|
for (var i = 1; i <= 6; i++) {
|
155
167
|
matches[i] = parseInt(matches[i], 10) || 0;
|
156
168
|
}
|
@@ -159,21 +171,25 @@ I18n.parseDate = function(d) {
|
|
159
171
|
matches[2] -= 1;
|
160
172
|
|
161
173
|
if (matches[7]) {
|
162
|
-
|
174
|
+
convertedDate = new Date(Date.UTC(matches[1], matches[2], matches[3], matches[4], matches[5], matches[6]));
|
163
175
|
} else {
|
164
|
-
|
176
|
+
convertedDate = new Date(matches[1], matches[2], matches[3], matches[4], matches[5], matches[6]);
|
165
177
|
}
|
166
|
-
} else if (typeof(
|
178
|
+
} else if (typeof(date) == "number") {
|
167
179
|
// UNIX timestamp
|
168
|
-
|
169
|
-
|
180
|
+
convertedDate = new Date();
|
181
|
+
convertedDate.setTime(date);
|
182
|
+
} else if (date.match(/\d+ \d+:\d+:\d+ [+-]\d+ \d+/)) {
|
183
|
+
// a valid javascript format with timezone info
|
184
|
+
convertedDate = new Date();
|
185
|
+
convertedDate.setTime(Date.parse(date))
|
170
186
|
} else {
|
171
187
|
// an arbitrary javascript string
|
172
|
-
|
173
|
-
|
188
|
+
convertedDate = new Date();
|
189
|
+
convertedDate.setTime(Date.parse(date));
|
174
190
|
}
|
175
191
|
|
176
|
-
return
|
192
|
+
return convertedDate;
|
177
193
|
};
|
178
194
|
|
179
195
|
I18n.toTime = function(scope, d) {
|
@@ -230,6 +246,7 @@ I18n.strftime = function(date, format) {
|
|
230
246
|
f = f.replace("%b", options.abbr_month_names[month]);
|
231
247
|
f = f.replace("%B", options.month_names[month]);
|
232
248
|
f = f.replace("%d", padding(day));
|
249
|
+
f = f.replace("%e", day);
|
233
250
|
f = f.replace("%-d", day);
|
234
251
|
f = f.replace("%H", padding(hour));
|
235
252
|
f = f.replace("%-H", hour);
|
metadata
CHANGED
@@ -1,105 +1,113 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-js
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Nando Vieira
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: i18n
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2154603060 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: fakeweb
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *2154603060
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fakeweb
|
27
|
+
requirement: &2154602640 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
35
33
|
type: :development
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: activesupport
|
39
34
|
prerelease: false
|
40
|
-
|
35
|
+
version_requirements: *2154602640
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
requirement: &2154602140 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
45
43
|
version: 3.0.0
|
46
44
|
type: :development
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rspec
|
50
45
|
prerelease: false
|
51
|
-
|
46
|
+
version_requirements: *2154602140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2154601640 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
51
|
+
requirements:
|
54
52
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 2.
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
57
55
|
type: :development
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: ruby-debug19
|
61
56
|
prerelease: false
|
62
|
-
|
57
|
+
version_requirements: *2154601640
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: ruby-debug19
|
60
|
+
requirement: &2154601260 !ruby/object:Gem::Requirement
|
63
61
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
68
66
|
type: :development
|
69
|
-
version_requirements: *id005
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: spec-js
|
72
67
|
prerelease: false
|
73
|
-
|
68
|
+
version_requirements: *2154601260
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: spec-js
|
71
|
+
requirement: &2154600720 !ruby/object:Gem::Requirement
|
74
72
|
none: false
|
75
|
-
requirements:
|
73
|
+
requirements:
|
76
74
|
- - ~>
|
77
|
-
- !ruby/object:Gem::Version
|
75
|
+
- !ruby/object:Gem::Version
|
78
76
|
version: 0.1.0.beta.0
|
79
77
|
type: :development
|
80
|
-
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2154600720
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rake
|
82
|
+
requirement: &2154600220 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - =
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.8.7
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2154600220
|
81
91
|
description: It's a small library to provide the Rails I18n translations on the Javascript.
|
82
|
-
email:
|
92
|
+
email:
|
83
93
|
- fnando.vieira@gmail.com
|
84
94
|
executables: []
|
85
|
-
|
86
95
|
extensions: []
|
87
|
-
|
88
96
|
extra_rdoc_files: []
|
89
|
-
|
90
|
-
files:
|
97
|
+
files:
|
91
98
|
- .gitignore
|
99
|
+
- .rspec
|
92
100
|
- Gemfile
|
93
101
|
- Gemfile.lock
|
94
102
|
- README.rdoc
|
95
103
|
- Rakefile
|
104
|
+
- config/i18n-js.yml
|
96
105
|
- i18n-js.gemspec
|
97
106
|
- lib/i18n-js.rb
|
107
|
+
- lib/i18n-js/engine.rb
|
98
108
|
- lib/i18n-js/railtie.rb
|
109
|
+
- lib/i18n-js/rake.rb
|
99
110
|
- lib/i18n-js/version.rb
|
100
|
-
- lib/tasks/i18n-js_tasks.rake
|
101
|
-
- source/i18n-js.yml
|
102
|
-
- source/i18n.js
|
103
111
|
- spec/i18n_spec.js
|
104
112
|
- spec/i18n_spec.rb
|
105
113
|
- spec/resources/custom_path.yml
|
@@ -110,34 +118,38 @@ files:
|
|
110
118
|
- spec/resources/no_scope.yml
|
111
119
|
- spec/resources/simple_scope.yml
|
112
120
|
- spec/spec_helper.rb
|
121
|
+
- vendor/assets/javascripts/i18n.js
|
113
122
|
homepage: http://rubygems.org/gems/i18n-js
|
114
123
|
licenses: []
|
115
|
-
|
116
124
|
post_install_message:
|
117
125
|
rdoc_options: []
|
118
|
-
|
119
|
-
require_paths:
|
126
|
+
require_paths:
|
120
127
|
- lib
|
121
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
129
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
version:
|
127
|
-
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
hash: -4305660274068506457
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
138
|
none: false
|
129
|
-
requirements:
|
130
|
-
- -
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version:
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: -4305660274068506457
|
133
146
|
requirements: []
|
134
|
-
|
135
147
|
rubyforge_project:
|
136
|
-
rubygems_version: 1.
|
148
|
+
rubygems_version: 1.8.5
|
137
149
|
signing_key:
|
138
150
|
specification_version: 3
|
139
151
|
summary: It's a small library to provide the Rails I18n translations on the Javascript.
|
140
|
-
test_files:
|
152
|
+
test_files:
|
141
153
|
- spec/i18n_spec.js
|
142
154
|
- spec/i18n_spec.rb
|
143
155
|
- spec/resources/custom_path.yml
|
data/source/i18n-js.yml
DELETED