i18n-js 0.1.6 → 1.0.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.
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +49 -0
- data/README.rdoc +24 -11
- data/Rakefile +9 -38
- data/i18n-js.gemspec +26 -0
- data/lib/i18n-js/version.rb +3 -3
- data/source/i18n.js +301 -266
- data/spec/i18n_spec.js +686 -0
- data/spec/i18n_spec.rb +169 -0
- data/{test → spec}/resources/custom_path.yml +0 -0
- data/{test → spec}/resources/default.yml +0 -0
- data/{test → spec}/resources/locales.yml +0 -0
- data/spec/resources/multiple_conditions.yml +6 -0
- data/{test → spec}/resources/multiple_files.yml +0 -0
- data/{test → spec}/resources/no_scope.yml +0 -0
- data/{test → spec}/resources/simple_scope.yml +0 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +6 -13
- metadata +103 -40
- data/init.rb +0 -1
- data/install.rb +0 -7
- data/test/i18n-test.html +0 -50
- data/test/i18n-test.js +0 -692
- data/test/i18n_js_test.rb +0 -154
- data/test/jsunittest/jsunittest.js +0 -1017
- data/test/jsunittest/unittest.css +0 -54
data/spec/i18n_spec.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
if File.basename(Rails.root) != "tmp"
|
4
|
+
warn <<-TXT
|
5
|
+
\e[31;5m
|
6
|
+
WARNING: That will remove your project!
|
7
|
+
Please go to #{File.expand_path(File.dirname(__FILE__) + "/..")} and run `rake spec`\e[0m
|
8
|
+
TXT
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
describe SimplesIdeias::I18n do
|
13
|
+
before do
|
14
|
+
# Remove temporary directory if already present
|
15
|
+
FileUtils.rm_r(Rails.root) if File.exist?(Rails.root)
|
16
|
+
|
17
|
+
# Create temporary directory to test the files generation
|
18
|
+
%w( config public/javascripts ).each do |path|
|
19
|
+
FileUtils.mkdir_p Rails.root.join(path)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Overwrite defaut locales path to use fixtures
|
23
|
+
I18n.load_path = [File.dirname(__FILE__) + "/resources/locales.yml"]
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
# Remove temporary directory
|
28
|
+
FileUtils.rm_r(Rails.root)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "copies the configuration file" do
|
32
|
+
File.should_not be_file(SimplesIdeias::I18n.config_file)
|
33
|
+
SimplesIdeias::I18n.setup!
|
34
|
+
File.should be_file(SimplesIdeias::I18n.config_file)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "keeps existing configuration file" do
|
38
|
+
File.open(SimplesIdeias::I18n.config_file, "w+") {|f| f << "ORIGINAL"}
|
39
|
+
SimplesIdeias::I18n.setup!
|
40
|
+
|
41
|
+
File.read(SimplesIdeias::I18n.config_file).should == "ORIGINAL"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "copies JavaScript library" do
|
45
|
+
path = Rails.root.join("public/javascripts/i18n.js")
|
46
|
+
|
47
|
+
File.should_not be_file(path)
|
48
|
+
SimplesIdeias::I18n.setup!
|
49
|
+
File.should be_file(path)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "loads configuration file" do
|
53
|
+
SimplesIdeias::I18n.setup!
|
54
|
+
|
55
|
+
SimplesIdeias::I18n.config?.should be_true
|
56
|
+
SimplesIdeias::I18n.config.should be_kind_of(HashWithIndifferentAccess)
|
57
|
+
SimplesIdeias::I18n.config.should_not be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it "exports messages to default path when configuration file doesn't exist" do
|
61
|
+
SimplesIdeias::I18n.export!
|
62
|
+
File.should be_file(Rails.root.join("public/javascripts/translations.js"))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "exports messages using the default configuration file" do
|
66
|
+
set_config "default.yml"
|
67
|
+
SimplesIdeias::I18n.should_receive(:save).with(translations, "public/javascripts/translations.js")
|
68
|
+
SimplesIdeias::I18n.export!
|
69
|
+
end
|
70
|
+
|
71
|
+
it "exports messages using custom output path" do
|
72
|
+
set_config "custom_path.yml"
|
73
|
+
SimplesIdeias::I18n.should_receive(:save).with(translations, "public/javascripts/translations/all.js")
|
74
|
+
SimplesIdeias::I18n.export!
|
75
|
+
end
|
76
|
+
|
77
|
+
it "sets default scope to * when not specified" do
|
78
|
+
set_config "no_scope.yml"
|
79
|
+
SimplesIdeias::I18n.should_receive(:save).with(translations, "public/javascripts/no_scope.js")
|
80
|
+
SimplesIdeias::I18n.export!
|
81
|
+
end
|
82
|
+
|
83
|
+
it "exports to multiple files" do
|
84
|
+
set_config "multiple_files.yml"
|
85
|
+
SimplesIdeias::I18n.export!
|
86
|
+
|
87
|
+
File.should be_file(Rails.root.join("public/javascripts/all.js"))
|
88
|
+
File.should be_file(Rails.root.join("public/javascripts/tudo.js"))
|
89
|
+
end
|
90
|
+
|
91
|
+
it "exports with multiple conditions" do
|
92
|
+
set_config "multiple_conditions.yml"
|
93
|
+
SimplesIdeias::I18n.export!
|
94
|
+
File.should be_file(Rails.root.join("public/javascripts/bitsnpieces.js"))
|
95
|
+
end
|
96
|
+
|
97
|
+
it "filters translations using scope *.date.formats" do
|
98
|
+
result = SimplesIdeias::I18n.filter(translations, "*.date.formats")
|
99
|
+
result[:en][:date].keys.should == [:formats]
|
100
|
+
result[:fr][:date].keys.should == [:formats]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "filters translations using scope [*.date.formats, *.number.currency.format]" do
|
104
|
+
result = SimplesIdeias::I18n.scoped_translations(["*.date.formats", "*.number.currency.format"])
|
105
|
+
result[:en].keys.collect(&:to_s).sort.should == %w[ date number ]
|
106
|
+
result[:fr].keys.collect(&:to_s).sort.should == %w[ date number ]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "filters translations using multi-star scope" do
|
110
|
+
result = SimplesIdeias::I18n.scoped_translations("*.*.formats")
|
111
|
+
|
112
|
+
result[:en].keys.collect(&:to_s).sort.should == %w[ date time ]
|
113
|
+
result[:fr].keys.collect(&:to_s).sort.should == %w[ date time ]
|
114
|
+
|
115
|
+
result[:en][:date].keys.should == [:formats]
|
116
|
+
result[:en][:time].keys.should == [:formats]
|
117
|
+
|
118
|
+
result[:fr][:date].keys.should == [:formats]
|
119
|
+
result[:fr][:time].keys.should == [:formats]
|
120
|
+
end
|
121
|
+
|
122
|
+
it "filters translations using alternated stars" do
|
123
|
+
result = SimplesIdeias::I18n.scoped_translations("*.admin.*.title")
|
124
|
+
|
125
|
+
result[:en][:admin].keys.collect(&:to_s).sort.should == %w[ edit show ]
|
126
|
+
result[:fr][:admin].keys.collect(&:to_s).sort.should == %w[ edit show ]
|
127
|
+
|
128
|
+
result[:en][:admin][:show][:title].should == "Show"
|
129
|
+
result[:fr][:admin][:show][:title].should == "Visualiser"
|
130
|
+
|
131
|
+
result[:en][:admin][:edit][:title].should == "Edit"
|
132
|
+
result[:fr][:admin][:edit][:title].should == "Editer"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "performs a deep merge" do
|
136
|
+
target = {:a => {:b => 1}}
|
137
|
+
result = SimplesIdeias::I18n.deep_merge(target, {:a => {:c => 2}})
|
138
|
+
|
139
|
+
result[:a].should == {:b => 1, :c => 2}
|
140
|
+
end
|
141
|
+
|
142
|
+
it "performs a banged deep merge" do
|
143
|
+
target = {:a => {:b => 1}}
|
144
|
+
SimplesIdeias::I18n.deep_merge!(target, {:a => {:c => 2}})
|
145
|
+
|
146
|
+
target[:a].should == {:b => 1, :c => 2}
|
147
|
+
end
|
148
|
+
|
149
|
+
it "updates the javascript library" do
|
150
|
+
FakeWeb.register_uri(:get, "http://github.com/fnando/i18n-js/raw/master/lib/i18n.js", :body => "UPDATED")
|
151
|
+
|
152
|
+
SimplesIdeias::I18n.setup!
|
153
|
+
SimplesIdeias::I18n.update!
|
154
|
+
File.read(SimplesIdeias::I18n.javascript_file).should == "UPDATED"
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
# Set the configuration as the current one
|
159
|
+
def set_config(path)
|
160
|
+
config = HashWithIndifferentAccess.new(YAML.load_file(File.dirname(__FILE__) + "/resources/#{path}"))
|
161
|
+
SimplesIdeias::I18n.should_receive(:config?).and_return(true)
|
162
|
+
SimplesIdeias::I18n.should_receive(:config).and_return(config)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Shortcut to SimplesIdeias::I18n.translations
|
166
|
+
def translations
|
167
|
+
SimplesIdeias::I18n.translations
|
168
|
+
end
|
169
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,14 +1,4 @@
|
|
1
|
-
require "
|
2
|
-
gem "test-unit"
|
3
|
-
require "test/unit"
|
4
|
-
require "mocha"
|
5
|
-
|
6
|
-
begin
|
7
|
-
require "active_support/all"
|
8
|
-
rescue LoadError
|
9
|
-
require "active_support"
|
10
|
-
end
|
11
|
-
|
1
|
+
require "active_support/all"
|
12
2
|
require "active_support/version"
|
13
3
|
require "active_support/test_case"
|
14
4
|
require "ostruct"
|
@@ -21,6 +11,9 @@ FakeWeb.allow_net_connect = false
|
|
21
11
|
|
22
12
|
# Stub Rails.root, so we don"t need to load the whole Rails environment.
|
23
13
|
# Be careful! The specified folder will be removed!
|
24
|
-
Rails = OpenStruct.new(
|
14
|
+
Rails = OpenStruct.new({
|
15
|
+
:root => Pathname.new(File.dirname(__FILE__) + "/tmp"),
|
16
|
+
:version => "0"
|
17
|
+
})
|
25
18
|
|
26
|
-
require
|
19
|
+
require "i18n-js"
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 6
|
10
|
-
version: 0.1.6
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Nando Vieira
|
@@ -15,48 +10,114 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2011-02-07 00:00:00 -02:00
|
19
14
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: i18n
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fakeweb
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: activesupport
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.0.0
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.5.0
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: ruby-debug19
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: spec-js
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.1.0.beta.0
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
description: It's a small library to provide the Rails I18n translations on the Javascript.
|
83
|
+
email:
|
84
|
+
- fnando.vieira@gmail.com
|
24
85
|
executables: []
|
25
86
|
|
26
87
|
extensions: []
|
27
88
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
89
|
+
extra_rdoc_files: []
|
90
|
+
|
30
91
|
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
31
95
|
- README.rdoc
|
32
96
|
- Rakefile
|
33
|
-
-
|
34
|
-
- install.rb
|
97
|
+
- i18n-js.gemspec
|
35
98
|
- lib/i18n-js.rb
|
36
99
|
- lib/i18n-js/railtie.rb
|
37
100
|
- lib/i18n-js/version.rb
|
38
101
|
- lib/tasks/i18n-js_tasks.rake
|
39
102
|
- source/i18n-js.yml
|
40
103
|
- source/i18n.js
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
- test/resources/simple_scope.yml
|
52
|
-
- test/test_helper.rb
|
104
|
+
- spec/i18n_spec.js
|
105
|
+
- spec/i18n_spec.rb
|
106
|
+
- spec/resources/custom_path.yml
|
107
|
+
- spec/resources/default.yml
|
108
|
+
- spec/resources/locales.yml
|
109
|
+
- spec/resources/multiple_conditions.yml
|
110
|
+
- spec/resources/multiple_files.yml
|
111
|
+
- spec/resources/no_scope.yml
|
112
|
+
- spec/resources/simple_scope.yml
|
113
|
+
- spec/spec_helper.rb
|
53
114
|
has_rdoc: true
|
54
|
-
homepage: http://
|
115
|
+
homepage: http://rubygems.org/gems/i18n-js
|
55
116
|
licenses: []
|
56
117
|
|
57
118
|
post_install_message:
|
58
|
-
rdoc_options:
|
59
|
-
|
119
|
+
rdoc_options: []
|
120
|
+
|
60
121
|
require_paths:
|
61
122
|
- lib
|
62
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -64,26 +125,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
125
|
requirements:
|
65
126
|
- - ">="
|
66
127
|
- !ruby/object:Gem::Version
|
67
|
-
hash: 3
|
68
|
-
segments:
|
69
|
-
- 0
|
70
128
|
version: "0"
|
71
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
130
|
none: false
|
73
131
|
requirements:
|
74
132
|
- - ">="
|
75
133
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
|
-
segments:
|
78
|
-
- 0
|
79
134
|
version: "0"
|
80
135
|
requirements: []
|
81
136
|
|
82
137
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
138
|
+
rubygems_version: 1.5.0
|
84
139
|
signing_key:
|
85
140
|
specification_version: 3
|
86
141
|
summary: It's a small library to provide the Rails I18n translations on the Javascript.
|
87
142
|
test_files:
|
88
|
-
-
|
89
|
-
-
|
143
|
+
- spec/i18n_spec.js
|
144
|
+
- spec/i18n_spec.rb
|
145
|
+
- spec/resources/custom_path.yml
|
146
|
+
- spec/resources/default.yml
|
147
|
+
- spec/resources/locales.yml
|
148
|
+
- spec/resources/multiple_conditions.yml
|
149
|
+
- spec/resources/multiple_files.yml
|
150
|
+
- spec/resources/no_scope.yml
|
151
|
+
- spec/resources/simple_scope.yml
|
152
|
+
- spec/spec_helper.rb
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "i18n-js"
|
data/install.rb
DELETED
data/test/i18n-test.html
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<title>JavaScript unit test file</title>
|
6
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
7
|
-
<script src="jsunittest/jsunittest.js" type="text/javascript"></script>
|
8
|
-
<link rel="stylesheet" href="jsunittest/unittest.css" type="text/css" />
|
9
|
-
|
10
|
-
<style type="text/css" media="screen">
|
11
|
-
#logger p {
|
12
|
-
background: #ffc;
|
13
|
-
padding: 5px;
|
14
|
-
}
|
15
|
-
</style>
|
16
|
-
<script type="text/javascript" charset="utf-8">
|
17
|
-
function log(name, message) {
|
18
|
-
var tag = document.getElementById("logger");
|
19
|
-
message = message.toString();
|
20
|
-
message = message.replace(/&/gm, "&");
|
21
|
-
message = message.replace(/</gm, "<");
|
22
|
-
message = message.replace(/>/gm, ">");
|
23
|
-
tag.innerHTML += "<p><strong>" + name + ":</strong> " + message + "</p>";
|
24
|
-
}
|
25
|
-
</script>
|
26
|
-
<script src="../source/i18n.js" type="text/javascript"></script>
|
27
|
-
</head>
|
28
|
-
<body>
|
29
|
-
|
30
|
-
<div id="content">
|
31
|
-
<div id="header">
|
32
|
-
<h1>JavaScript unit test file</h1>
|
33
|
-
<p>
|
34
|
-
This file tests <strong>i18n.js</strong>.
|
35
|
-
</p>
|
36
|
-
</div>
|
37
|
-
|
38
|
-
<!-- Log output (one per Runner, via {testLog: "testlog"} option)-->
|
39
|
-
<div id="testlog"></div>
|
40
|
-
|
41
|
-
<!-- General debugger -->
|
42
|
-
<div id="logger"></div>
|
43
|
-
|
44
|
-
<!-- Put sample/test html here -->
|
45
|
-
<div id="sample">
|
46
|
-
</div>
|
47
|
-
</div>
|
48
|
-
<script src="i18n-test.js" type="text/javascript" charset="utf-8"></script>
|
49
|
-
</body>
|
50
|
-
</html>
|