web_translate_it 1.10.2 → 2.0.0.rc2
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/history.md +13 -0
- data/lib/web_translate_it.rb +2 -0
- data/lib/web_translate_it/string.rb +197 -33
- data/lib/web_translate_it/term.rb +175 -29
- data/lib/web_translate_it/term_translation.rb +68 -14
- data/lib/web_translate_it/translation.rb +46 -24
- data/lib/web_translate_it/util.rb +1 -2
- data/lib/web_translate_it/util/hash_util.rb +24 -4
- data/readme.md +20 -22
- data/spec/web_translate_it/string_spec.rb +127 -0
- data/spec/web_translate_it/term_spec.rb +114 -0
- data/version +1 -0
- metadata +94 -81
- data/spec/web_translate_it/configuration_spec.rb +0 -60
- data/spec/web_translate_it/translation_file_spec.rb +0 -52
- data/spec/web_translate_it/util_spec.rb +0 -10
- data/spec/web_translate_it_spec.rb +0 -26
- data/version.yml +0 -4
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WebTranslateIt::Term do
|
4
|
+
|
5
|
+
let(:api_key) { "19875cfdd4f169b33e0ffab32cfb0bbb9e33d653" }
|
6
|
+
|
7
|
+
describe "#initialize" do
|
8
|
+
it "should assign api_key and many parameters" do
|
9
|
+
term = WebTranslateIt::Term.new(api_key, { "id" => 1234, "text" => "bacon"})
|
10
|
+
term.api_key.should == api_key
|
11
|
+
term.id.should == 1234
|
12
|
+
term.text.should == "bacon"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#save" do
|
17
|
+
it "should create a new Term" do
|
18
|
+
WebTranslateIt::Util.http_connection do |connection|
|
19
|
+
term = WebTranslateIt::Term.new(api_key, { "text" => "Term", "description" => "A description" })
|
20
|
+
term.save(connection)
|
21
|
+
term.id.should_not be_nil
|
22
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
23
|
+
term_fetched.should_not be_nil
|
24
|
+
term_fetched.should be_a(WebTranslateIt::Term)
|
25
|
+
term_fetched.id.should == term.id
|
26
|
+
term.delete(connection)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should update an existing Term" do
|
31
|
+
WebTranslateIt::Util.http_connection do |connection|
|
32
|
+
term = WebTranslateIt::Term.new(api_key, { "text" => "Term", "description" => "A description" })
|
33
|
+
term.save(connection)
|
34
|
+
term.text = "A Term"
|
35
|
+
term.save(connection)
|
36
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
37
|
+
term_fetched.text.should == "A Term"
|
38
|
+
term.delete(connection)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create a new Term with a TermTranslation" do
|
43
|
+
translation1 = WebTranslateIt::TermTranslation.new(api_key, { "locale" => "fr", "text" => "Bonjour" })
|
44
|
+
translation2 = WebTranslateIt::TermTranslation.new(api_key, { "locale" => "fr", "text" => "Salut" })
|
45
|
+
|
46
|
+
term = WebTranslateIt::Term.new(api_key, { "text" => "Hello", "translations" => [translation1, translation2] })
|
47
|
+
WebTranslateIt::Util.http_connection do |connection|
|
48
|
+
term.save(connection)
|
49
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
50
|
+
term_fetched.translation_for(connection, "fr").should_not be_nil
|
51
|
+
term_fetched.translation_for(connection, "fr")[0].text.should == "Bonjour"
|
52
|
+
term_fetched.translation_for(connection, "fr")[1].text.should == "Salut"
|
53
|
+
term_fetched.translation_for(connection, "es").should be_nil
|
54
|
+
term.delete(connection)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should update a Term and save its Translation" do
|
59
|
+
translation1 = WebTranslateIt::TermTranslation.new(api_key, { "locale" => "fr", "text" => "Bonjour" })
|
60
|
+
translation2 = WebTranslateIt::TermTranslation.new(api_key, { "locale" => "fr", "text" => "Salut" })
|
61
|
+
|
62
|
+
term = WebTranslateIt::Term.new(api_key, { "text" => "Hi!" })
|
63
|
+
WebTranslateIt::Util.http_connection do |connection|
|
64
|
+
term.save(connection)
|
65
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
66
|
+
term_fetched.translation_for(connection, "fr").should be_nil
|
67
|
+
|
68
|
+
term_fetched.translations = [translation1, translation2]
|
69
|
+
term_fetched.save(connection)
|
70
|
+
|
71
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
72
|
+
term_fetched.translation_for(connection, "fr").should_not be_nil
|
73
|
+
term_fetched.translation_for(connection, "fr")[0].text.should == "Bonjour"
|
74
|
+
term_fetched.translation_for(connection, "fr")[1].text.should == "Salut"
|
75
|
+
term.delete(connection)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#delete" do
|
81
|
+
it "should delete a Term" do
|
82
|
+
term = WebTranslateIt::Term.new(api_key, { "text" => "bacon" })
|
83
|
+
WebTranslateIt::Util.http_connection do |connection|
|
84
|
+
term.save(connection)
|
85
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
86
|
+
term_fetched.should_not be_nil
|
87
|
+
|
88
|
+
term_fetched.delete(connection)
|
89
|
+
term_fetched = WebTranslateIt::Term.find(connection, api_key, term.id)
|
90
|
+
term_fetched.should be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#find_all" do
|
96
|
+
it "should fetch many terms" do
|
97
|
+
WebTranslateIt::Util.http_connection do |connection|
|
98
|
+
term1 = WebTranslateIt::Term.new(api_key, { "text" => "bacon" })
|
99
|
+
term1.save(connection)
|
100
|
+
term2 = WebTranslateIt::Term.new(api_key, { "text" => "tart" })
|
101
|
+
term2.save(connection)
|
102
|
+
term3 = WebTranslateIt::Term.new(api_key, { "text" => "bacon tart" })
|
103
|
+
term3.save(connection)
|
104
|
+
|
105
|
+
terms = WebTranslateIt::Term.find_all(connection, api_key)
|
106
|
+
terms.count.should == 3
|
107
|
+
|
108
|
+
term1.delete(connection)
|
109
|
+
term2.delete(connection)
|
110
|
+
term3.delete(connection)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0.rc2
|
metadata
CHANGED
@@ -1,84 +1,109 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_translate_it
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 10
|
9
|
-
- 2
|
10
|
-
version: 1.10.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.rc2
|
5
|
+
prerelease: 6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- Édouard Brière
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: multipart-post
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 21
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 1
|
32
|
-
- 3
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 1.1.3
|
34
22
|
type: :runtime
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
37
31
|
name: trollop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.16.2
|
38
|
+
type: :runtime
|
38
39
|
prerelease: false
|
39
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
|
-
requirements:
|
42
|
+
requirements:
|
42
43
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 83
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 16
|
48
|
-
- 2
|
44
|
+
- !ruby/object:Gem::Version
|
49
45
|
version: 1.16.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
50
54
|
type: :runtime
|
51
|
-
|
52
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
53
63
|
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.6.0
|
70
|
+
type: :development
|
54
71
|
prerelease: false
|
55
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
73
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 23
|
61
|
-
segments:
|
62
|
-
- 2
|
63
|
-
- 6
|
64
|
-
- 0
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
65
77
|
version: 2.6.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard-rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
66
86
|
type: :development
|
67
|
-
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
68
94
|
description:
|
69
95
|
email: edouard@atelierconvivialite.com
|
70
|
-
executables:
|
96
|
+
executables:
|
71
97
|
- wti
|
72
98
|
extensions: []
|
73
|
-
|
74
|
-
extra_rdoc_files:
|
99
|
+
extra_rdoc_files:
|
75
100
|
- history.md
|
76
101
|
- readme.md
|
77
|
-
files:
|
102
|
+
files:
|
78
103
|
- history.md
|
79
104
|
- license
|
80
105
|
- readme.md
|
81
|
-
- version
|
106
|
+
- version
|
82
107
|
- examples/en.yml
|
83
108
|
- examples/locale.rb
|
84
109
|
- lib/web_translate_it/auto_fetch.rb
|
@@ -105,49 +130,37 @@ files:
|
|
105
130
|
- spec/examples/config/translation.yml
|
106
131
|
- spec/examples/en.yml
|
107
132
|
- spec/spec_helper.rb
|
108
|
-
- spec/web_translate_it/
|
109
|
-
- spec/web_translate_it/
|
110
|
-
- spec/web_translate_it/util_spec.rb
|
111
|
-
- spec/web_translate_it_spec.rb
|
133
|
+
- spec/web_translate_it/string_spec.rb
|
134
|
+
- spec/web_translate_it/term_spec.rb
|
112
135
|
homepage: https://webtranslateit.com
|
113
136
|
licenses: []
|
114
|
-
|
115
137
|
post_install_message:
|
116
|
-
rdoc_options:
|
138
|
+
rdoc_options:
|
117
139
|
- --main
|
118
140
|
- readme.md
|
119
|
-
require_paths:
|
141
|
+
require_paths:
|
120
142
|
- lib
|
121
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
144
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
|
128
|
-
- 0
|
129
|
-
version: "0"
|
130
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
150
|
none: false
|
132
|
-
requirements:
|
133
|
-
- -
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
|
136
|
-
segments:
|
137
|
-
- 0
|
138
|
-
version: "0"
|
151
|
+
requirements:
|
152
|
+
- - ! '>'
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 1.3.1
|
139
155
|
requirements: []
|
140
|
-
|
141
156
|
rubyforge_project:
|
142
|
-
rubygems_version: 1.8.
|
157
|
+
rubygems_version: 1.8.22
|
143
158
|
signing_key:
|
144
159
|
specification_version: 3
|
145
160
|
summary: A CLI to sync locale files with webtranslateit.com.
|
146
|
-
test_files:
|
161
|
+
test_files:
|
147
162
|
- spec/examples/config/translation.yml
|
148
163
|
- spec/examples/en.yml
|
149
164
|
- spec/spec_helper.rb
|
150
|
-
- spec/web_translate_it/
|
151
|
-
- spec/web_translate_it/
|
152
|
-
- spec/web_translate_it/util_spec.rb
|
153
|
-
- spec/web_translate_it_spec.rb
|
165
|
+
- spec/web_translate_it/string_spec.rb
|
166
|
+
- spec/web_translate_it/term_spec.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WebTranslateIt::Configuration do
|
4
|
-
describe "#initialize" do
|
5
|
-
subject { WebTranslateIt::Configuration::Rails = OpenStruct.new(:root => Pathname.new(File.dirname(__FILE__) + "/../examples")) }
|
6
|
-
|
7
|
-
it "should fetch and not blow up" do
|
8
|
-
expect{ WebTranslateIt::Configuration.new }.to_not raise_error
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should load the content of the YAML file" do
|
12
|
-
config_hash = {
|
13
|
-
"api_key" => "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2",
|
14
|
-
"ignore_locales" => "en_GB"
|
15
|
-
}
|
16
|
-
YAML.should_receive(:load_file).and_return(config_hash)
|
17
|
-
WebTranslateIt::Configuration.new(File.dirname(__FILE__) + '/../..', '.wti')
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should assign the API key, files" do
|
21
|
-
configuration = WebTranslateIt::Configuration.new
|
22
|
-
configuration.api_key.should == '4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2'
|
23
|
-
configuration.files.first.should be_a(WebTranslateIt::TranslationFile)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#set_locales_to_ignore" do
|
28
|
-
let(:configuration) { WebTranslateIt::Configuration.new }
|
29
|
-
subject { WebTranslateIt::Configuration::Rails = OpenStruct.new(:root => Pathname.new(File.dirname(__FILE__) + "/../examples")) }
|
30
|
-
|
31
|
-
it "should return an array" do
|
32
|
-
config_hash = { 'ignore_locales' => 'en' }
|
33
|
-
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should not blow up if no locales are given" do
|
37
|
-
config_hash = { 'ignore_locales' => nil }
|
38
|
-
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
39
|
-
configuration.set_locales_to_ignore(config_hash).should == []
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return an array of 2 elements if given array of strings" do
|
43
|
-
config_hash = { 'ignore_locales' => ['en', 'fr'] }
|
44
|
-
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
45
|
-
configuration.set_locales_to_ignore(config_hash).should == ['en', 'fr']
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return an array of 1 element if given a symbol" do
|
49
|
-
config_hash = { 'ignore_locales' => :en }
|
50
|
-
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
51
|
-
configuration.set_locales_to_ignore(config_hash).should == ['en']
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should return an array of 2 element if given an array of symbol and string" do
|
55
|
-
config_hash = { 'ignore_locales' => [:en, 'fr'] }
|
56
|
-
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
57
|
-
configuration.set_locales_to_ignore(config_hash).should == ['en', 'fr']
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WebTranslateIt::TranslationFile do
|
4
|
-
|
5
|
-
describe "#initialize" do
|
6
|
-
it "should assign id, file_path and api_key" do
|
7
|
-
tr_file = WebTranslateIt::TranslationFile.new(2267, "examples/en.yml", 'fr', "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2")
|
8
|
-
tr_file.id.should == 2267
|
9
|
-
tr_file.file_path.should == "examples/en.yml"
|
10
|
-
tr_file.api_key.should == "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#fetch" do
|
15
|
-
let(:translation_file) { WebTranslateIt::TranslationFile.new(2267, "examples/en.yml", 'fr', "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2", Time.now) }
|
16
|
-
|
17
|
-
it "should prepare a HTTP request and get a 200 OK if the language file is stale" do
|
18
|
-
file = mock(File)
|
19
|
-
file.stub(:puts => true, :close => true)
|
20
|
-
File.stub(:exist? => true, :mtime => Time.at(0), :new => file)
|
21
|
-
translation_file.fetch.should include "OK"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should prepare a HTTP request and get a 200 OK if the language file is stale using the force download parameter" do
|
25
|
-
file = mock(File)
|
26
|
-
file.stub(:puts => true, :close => true)
|
27
|
-
File.stub(:exist? => true, :mtime => Time.at(0), :new => file)
|
28
|
-
translation_file.fetch(true).should include "OK"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should prepare a HTTP request and get a 200 OK if the language file is fresh using the force download parameter" do
|
32
|
-
file = mock(File)
|
33
|
-
file.stub(:puts => true, :close => true)
|
34
|
-
File.stub(:exist? => true, :mtime => Time.now, :new => file)
|
35
|
-
translation_file.fetch(true).should include "OK"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#upload" do
|
40
|
-
let(:translation_file) { WebTranslateIt::TranslationFile.new(2267, "examples/en.yml", 'fr', "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2") }
|
41
|
-
|
42
|
-
it "should prepare a HTTP request and get a 200 OK" do
|
43
|
-
translation_file.stub(:file_path => File.join(File.dirname(__FILE__), '..', 'examples', 'en.yml'))
|
44
|
-
translation_file.upload
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should fail if the file does not exist" do
|
48
|
-
translation_file.stub(:file_path => File.join('something', 'that', 'does', 'not', 'exist'))
|
49
|
-
expect { @translation_file.upload }.to raise_error
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|