web_translate_it 2.6.1 → 2.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/history.md +9 -0
- data/lib/web_translate_it/command_line.rb +19 -7
- data/lib/web_translate_it/configuration.rb +1 -1
- data/lib/web_translate_it/translation_file.rb +2 -2
- data/lib/web_translate_it/util/array_util.rb +1 -1
- data/readme.md +1 -1
- metadata +5 -17
- data/spec/examples/config/translation.yml +0 -9
- data/spec/examples/en.yml +0 -38
- data/spec/spec_helper.rb +0 -11
- data/spec/web_translate_it/auto_fetch_spec.rb +0 -47
- data/spec/web_translate_it/string_spec.rb +0 -153
- data/spec/web_translate_it/term_spec.rb +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b4f8260eedb1c889b34365fbb4d5e5f00b4907c52068a5f9ee1271eac7e0aa8
|
4
|
+
data.tar.gz: b872158814a7a958c873ddb603651b14aab8a2809c5ee42fbc7398d01fe71218
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e71ac4f5c76fb436583cd10b1f2092528eb5204a4b777a97b611eff2e55600c07f192c4844794d20c8e5dc800af5e0c73d308f074dc643917173efd5a0703e6
|
7
|
+
data.tar.gz: 5955c786b2a7f69f55e9ac9126d0a4637a4ecb9e286b9d810efdb1a5c58450cf183dee71601eb35454798c244c8d098f8af635e25988a4a1b30935e8eeb5fc11
|
data/history.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## Version 2.6.3 / 2022-06-14
|
2
|
+
|
3
|
+
* Fix deprecation warning. #181
|
4
|
+
* Set minimum ruby version to 2.6. It is [EOL since December 2018](https://endoflife.date/ruby), but it’s still the default ruby shipped with Mac OS Monterey.
|
5
|
+
|
6
|
+
## Version 2.6.2 / 2022-04-05
|
7
|
+
|
8
|
+
* Fix `wti init` command with ruby 3.1. #177
|
9
|
+
|
1
10
|
## Version 2.6.1 / 2022-03-09
|
2
11
|
|
3
12
|
* Display error message for `before_pull`, `after_pull`, `before_push`, `after_push` hooks.
|
@@ -294,7 +294,11 @@ module WebTranslateIt
|
|
294
294
|
path = Util.ask(' Path to configuration file:', '.wti')
|
295
295
|
end
|
296
296
|
FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
|
297
|
-
project =
|
297
|
+
project = if RUBY_VERSION >= '3.1'
|
298
|
+
YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
|
299
|
+
else
|
300
|
+
YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
301
|
+
end
|
298
302
|
project_info = project['project']
|
299
303
|
if File.exist?(path) && !File.writable?(path)
|
300
304
|
puts StringUtil.failure("Error: `#{path}` file is not writable.")
|
@@ -414,24 +418,32 @@ module WebTranslateIt
|
|
414
418
|
|
415
419
|
def generate_configuration(api_key, project_info)
|
416
420
|
<<~FILE
|
421
|
+
# Required - The Project API Token from WebTranslateIt.com
|
422
|
+
# More information: https://github.com/webtranslateit/webtranslateit/wiki#configuration-file
|
423
|
+
|
417
424
|
api_key: #{api_key}
|
418
425
|
|
419
|
-
# Optional
|
426
|
+
# Optional - Locales not to sync with WebTranslateIt.
|
427
|
+
# Takes a string, a symbol, or an array of string or symbol.
|
428
|
+
|
429
|
+
# ignore_locales: [#{project_info['source_locale']['code']}]
|
430
|
+
|
431
|
+
# Optional - Locales to sync with WebTranslateIt.
|
420
432
|
# Takes a string, a symbol, or an array of string or symbol.
|
421
|
-
# More information here: https://github.com/AtelierConvivialite/webtranslateit/wiki
|
422
|
-
# ignore_locales: '#{project_info['source_locale']['code']}'
|
423
433
|
|
424
|
-
# Or if you prefer a list of locales to sync with WebTranslateIt:
|
425
434
|
# needed_locales: #{project_info['target_locales'].map { |locale| locale['code'] }}
|
426
435
|
|
427
436
|
# Optional: files not to sync with WebTranslateIt.
|
428
437
|
# Takes an array of globs.
|
438
|
+
|
429
439
|
# ignore_files: ['somefile*.csv']
|
430
440
|
|
431
|
-
# Optional
|
441
|
+
# Optional - Hooks
|
442
|
+
# Takes a string containing a command to run.
|
443
|
+
|
432
444
|
# before_pull: "echo 'some unix command'" # Command executed before pulling files
|
433
445
|
# after_pull: "touch tmp/restart.txt" # Command executed after pulling files
|
434
|
-
|
446
|
+
|
435
447
|
# before_push: "echo 'some unix command'" # Command executed before pushing files
|
436
448
|
# after_push: "touch tmp/restart.txt" # Command executed after pushing files
|
437
449
|
|
@@ -17,7 +17,7 @@ module WebTranslateIt
|
|
17
17
|
self.path = root_path
|
18
18
|
self.logger = logger
|
19
19
|
if File.exist?(File.expand_path(path_to_config_file, path))
|
20
|
-
self.api_key = ENV
|
20
|
+
self.api_key = ENV.fetch('WTI_PROJECT_API_KEY') { configuration['api_key'] }
|
21
21
|
self.before_pull = configuration['before_pull']
|
22
22
|
self.after_pull = configuration['after_pull']
|
23
23
|
self.before_push = configuration['before_push']
|
@@ -99,7 +99,7 @@ module WebTranslateIt
|
|
99
99
|
if File.exist?(file_path)
|
100
100
|
if force || (remote_checksum != local_checksum)
|
101
101
|
File.open(file_path) do |file|
|
102
|
-
params = { 'file' => UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'low_priority' => low_priority, 'minor_changes' => minor_changes }
|
102
|
+
params = { 'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'merge' => merge, 'ignore_missing' => ignore_missing, 'label' => label, 'low_priority' => low_priority, 'minor_changes' => minor_changes }
|
103
103
|
params['name'] = destination_path unless destination_path.nil?
|
104
104
|
params['rename_others'] = rename_others
|
105
105
|
request = Net::HTTP::Put::Multipart.new(api_url, params)
|
@@ -150,7 +150,7 @@ module WebTranslateIt
|
|
150
150
|
display.push "#{StringUtil.checksumify(local_checksum.to_s)}..[ ]"
|
151
151
|
if File.exist?(file_path)
|
152
152
|
File.open(file_path) do |file|
|
153
|
-
request = Net::HTTP::Post::Multipart.new(api_url_for_create, { 'name' => file_path, 'file' => UploadIO.new(file, 'text/plain', file.path), 'low_priority' => low_priority })
|
153
|
+
request = Net::HTTP::Post::Multipart.new(api_url_for_create, { 'name' => file_path, 'file' => Multipart::Post::UploadIO.new(file, 'text/plain', file.path), 'low_priority' => low_priority })
|
154
154
|
WebTranslateIt::Util.add_fields(request)
|
155
155
|
display.push Util.handle_response(http_connection.request(request))
|
156
156
|
puts ArrayUtil.to_columns(display)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ArrayUtil
|
2
2
|
def self.to_columns(arr)
|
3
3
|
if arr[0][0] == '*'
|
4
|
-
"*#{StringUtil.backward_truncate(arr[0][1
|
4
|
+
"*#{StringUtil.backward_truncate(arr[0][1..])} | #{arr[1]} #{arr[2]}\n"
|
5
5
|
else
|
6
6
|
" #{StringUtil.backward_truncate(arr[0])} | #{arr[1]} #{arr[2]}\n"
|
7
7
|
end
|
data/readme.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# WebTranslateIt Synchronization Tool : wti
|
2
2
|
|
3
|
-
[RubyDoc](https://rubydoc.info/
|
3
|
+
[RubyDoc](https://www.rubydoc.info/gems/web_translate_it/) |
|
4
4
|
[Report a bug](https://github.com/webtranslateit/webtranslateit/issues) |
|
5
5
|
[Support](https://webtranslateit.com/support) |
|
6
6
|
[WebTranslateIt.com Homepage](https://webtranslateit.com)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_translate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Briere
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -156,12 +156,6 @@ files:
|
|
156
156
|
- man/wti.1.html
|
157
157
|
- man/wti.1.ron
|
158
158
|
- readme.md
|
159
|
-
- spec/examples/config/translation.yml
|
160
|
-
- spec/examples/en.yml
|
161
|
-
- spec/spec_helper.rb
|
162
|
-
- spec/web_translate_it/auto_fetch_spec.rb
|
163
|
-
- spec/web_translate_it/string_spec.rb
|
164
|
-
- spec/web_translate_it/term_spec.rb
|
165
159
|
homepage: https://webtranslateit.com
|
166
160
|
licenses:
|
167
161
|
- MIT
|
@@ -183,21 +177,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
177
|
requirements:
|
184
178
|
- - ">="
|
185
179
|
- !ruby/object:Gem::Version
|
186
|
-
version: '2.
|
180
|
+
version: '2.6'
|
187
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
182
|
requirements:
|
189
183
|
- - ">="
|
190
184
|
- !ruby/object:Gem::Version
|
191
185
|
version: '0'
|
192
186
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
187
|
+
rubygems_version: 3.2.33
|
194
188
|
signing_key:
|
195
189
|
specification_version: 4
|
196
190
|
summary: A CLI tool to sync locale files with WebTranslateIt.com.
|
197
|
-
test_files:
|
198
|
-
- spec/web_translate_it/auto_fetch_spec.rb
|
199
|
-
- spec/web_translate_it/term_spec.rb
|
200
|
-
- spec/web_translate_it/string_spec.rb
|
201
|
-
- spec/spec_helper.rb
|
202
|
-
- spec/examples/config/translation.yml
|
203
|
-
- spec/examples/en.yml
|
191
|
+
test_files: []
|
data/spec/examples/en.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
activerecord:
|
3
|
-
errors:
|
4
|
-
templates:
|
5
|
-
header:
|
6
|
-
one: "1 error prohibited this {{model}} from being saved"
|
7
|
-
other: "{{count}} errors prohibited this {{model}} from being saved"
|
8
|
-
body: "there were problems with the following fields:"
|
9
|
-
messages:
|
10
|
-
accepted: "must be accepted"
|
11
|
-
blank: "can't be blank"
|
12
|
-
confirmation: "doesn't match confirmation"
|
13
|
-
empty: "can't be empty"
|
14
|
-
equal_to: "must be equal to {{count}}"
|
15
|
-
even: "must be even"
|
16
|
-
exclusion: "is reserved"
|
17
|
-
greater_than: "must be greater than {{count}}"
|
18
|
-
greater_than_or_equal_to: "must be greater than or equal to {{count}}"
|
19
|
-
inclusion: "is not included in the list"
|
20
|
-
invalid: "is invalid"
|
21
|
-
less_than: "must be less than {{count}}"
|
22
|
-
less_than_or_equal_to: "must be less than or equal to {{count}}"
|
23
|
-
not_a_number: "is not a number"
|
24
|
-
odd: "must be odd"
|
25
|
-
taken: "is already taken"
|
26
|
-
too_long: "is too long (maximum is {{count}} characters)"
|
27
|
-
too_short: "is too short (minimum is {{count}} characters)"
|
28
|
-
wrong_length: "is the wrong length (should be {{count}} characters)"
|
29
|
-
models:
|
30
|
-
invitation:
|
31
|
-
attributes:
|
32
|
-
email:
|
33
|
-
user_already_invited: "This user has already been invited"
|
34
|
-
user_already_member: "This user is already a member"
|
35
|
-
project_file:
|
36
|
-
attributes:
|
37
|
-
file:
|
38
|
-
file_format_not_supported: "Sorry, we currenly support only Gettext .pot/.po, .yml/.yaml and .strings"
|
data/spec/spec_helper.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WebTranslateIt::AutoFetch do
|
4
|
-
let(:application) { double(:application, call: []) }
|
5
|
-
|
6
|
-
let(:env) do
|
7
|
-
{ 'PATH_INFO' => path }
|
8
|
-
end
|
9
|
-
|
10
|
-
subject { described_class.new(application) }
|
11
|
-
|
12
|
-
before { WebTranslateIt.stub(:fetch_translations) }
|
13
|
-
|
14
|
-
after { subject.call(env) }
|
15
|
-
|
16
|
-
context 'path is /' do
|
17
|
-
let(:path) { '/' }
|
18
|
-
|
19
|
-
it 'should call the application' do
|
20
|
-
application.should_receive(:call).with(env)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should update the translations' do
|
24
|
-
WebTranslateIt.should_receive(:fetch_translations)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should reload the I18n definitions' do
|
28
|
-
I18n.should_receive(:reload!)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'path is /assets/application.js' do
|
33
|
-
let(:path) { '/assets/application.js' }
|
34
|
-
|
35
|
-
it 'should call the application' do
|
36
|
-
application.should_receive(:call).with(env)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should not update the translations' do
|
40
|
-
WebTranslateIt.should_not_receive(:fetch_translations)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should not reload the I18n definitions' do
|
44
|
-
I18n.should_not_receive(:reload!)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WebTranslateIt::String do
|
4
|
-
let(:api_key) { 'proj_pvt_glzDR250FLXlMgJPZfEyHQ' }
|
5
|
-
|
6
|
-
describe '#initialize' do
|
7
|
-
it 'should assign api_key and many parameters' do
|
8
|
-
string = WebTranslateIt::String.new({ 'id' => 1234, 'key' => 'bacon' })
|
9
|
-
string.id.should == 1234
|
10
|
-
string.key.should == 'bacon'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should assign parameters using symbols' do
|
14
|
-
string = WebTranslateIt::String.new({ id: 1234, key: 'bacon' })
|
15
|
-
string.id.should == 1234
|
16
|
-
string.key.should == 'bacon'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#save' do
|
21
|
-
it 'should create a new String' do
|
22
|
-
WebTranslateIt::Connection.new(api_key) do
|
23
|
-
string = WebTranslateIt::String.new({ 'key' => 'bacon' })
|
24
|
-
string.save
|
25
|
-
string.id.should_not be_nil
|
26
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
27
|
-
string_fetched.should_not be_nil
|
28
|
-
string_fetched.should be_a(WebTranslateIt::String)
|
29
|
-
string_fetched.id.should == string.id
|
30
|
-
string.delete
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should update an existing String' do
|
35
|
-
WebTranslateIt::Connection.new(api_key) do
|
36
|
-
string = WebTranslateIt::String.new({ 'key' => 'bacony' })
|
37
|
-
string.save
|
38
|
-
string.key = 'bacon changed'
|
39
|
-
string.save
|
40
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
41
|
-
string_fetched.key.should == 'bacon changed'
|
42
|
-
string.delete
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should create a new String with Translation' do
|
47
|
-
translation1 = WebTranslateIt::Translation.new({ 'locale' => 'en', 'text' => 'Hello' })
|
48
|
-
translation2 = WebTranslateIt::Translation.new({ 'locale' => 'fr', 'text' => 'Bonjour' })
|
49
|
-
|
50
|
-
string = WebTranslateIt::String.new({ 'key' => 'bacon', 'translations' => [translation1, translation2] })
|
51
|
-
WebTranslateIt::Connection.new(api_key) do
|
52
|
-
string.save
|
53
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
54
|
-
string_fetched.translation_for('en').should_not be_nil
|
55
|
-
string_fetched.translation_for('en').text.should == 'Hello'
|
56
|
-
string_fetched.translation_for('fr').should_not be_nil
|
57
|
-
string_fetched.translation_for('fr').text.should == 'Bonjour'
|
58
|
-
string_fetched.translation_for('es').should be_nil
|
59
|
-
string.delete
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should update a String and save its Translation' do
|
64
|
-
translation1 = WebTranslateIt::Translation.new({ 'locale' => 'en', 'text' => 'Hello' })
|
65
|
-
translation2 = WebTranslateIt::Translation.new({ 'locale' => 'fr', 'text' => 'Bonjour' })
|
66
|
-
|
67
|
-
string = WebTranslateIt::String.new({ 'key' => 'bacon' })
|
68
|
-
WebTranslateIt::Connection.new(api_key) do
|
69
|
-
string.save
|
70
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
71
|
-
string_fetched.translation_for('fr').should be_nil
|
72
|
-
|
73
|
-
string_fetched.translations = [translation1, translation2]
|
74
|
-
string_fetched.save
|
75
|
-
|
76
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
77
|
-
string_fetched.translation_for('en').should_not be_nil
|
78
|
-
string_fetched.translation_for('en').text.should == 'Hello'
|
79
|
-
string_fetched.translation_for('fr').should_not be_nil
|
80
|
-
string_fetched.translation_for('fr').text.should == 'Bonjour'
|
81
|
-
string.delete
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#delete' do
|
87
|
-
it 'should delete a String' do
|
88
|
-
string = WebTranslateIt::String.new({ 'key' => 'bacon' })
|
89
|
-
WebTranslateIt::Connection.new(api_key) do
|
90
|
-
string.save
|
91
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
92
|
-
string_fetched.should_not be_nil
|
93
|
-
|
94
|
-
string_fetched.delete
|
95
|
-
WebTranslateIt::String.find(string.id).should be_nil
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#find_all' do
|
101
|
-
it 'should find many strings' do
|
102
|
-
WebTranslateIt::Connection.new(api_key) do
|
103
|
-
string1 = WebTranslateIt::String.new({ 'key' => 'one two three' })
|
104
|
-
string1.save
|
105
|
-
string2 = WebTranslateIt::String.new({ 'key' => 'four five six' })
|
106
|
-
string2.save
|
107
|
-
string3 = WebTranslateIt::String.new({ 'key' => 'six seven eight' })
|
108
|
-
string3.save
|
109
|
-
|
110
|
-
strings = WebTranslateIt::String.find_all({ 'key' => 'six' })
|
111
|
-
strings.count.should == 2
|
112
|
-
strings[0].key.should == 'four five six'
|
113
|
-
strings[1].key.should == 'six seven eight'
|
114
|
-
|
115
|
-
strings = WebTranslateIt::String.find_all({ key: 'six' })
|
116
|
-
strings.count.should == 2
|
117
|
-
strings[0].key.should == 'four five six'
|
118
|
-
strings[1].key.should == 'six seven eight'
|
119
|
-
|
120
|
-
strings = WebTranslateIt::String.find_all({ 'key' => 'eight' })
|
121
|
-
strings.count.should == 1
|
122
|
-
strings[0].key.should == 'six seven eight'
|
123
|
-
|
124
|
-
strings = WebTranslateIt::String.find_all({ 'key' => 'three' })
|
125
|
-
strings.count.should == 1
|
126
|
-
strings[0].key.should == 'one two three'
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe '#translation_for' do
|
132
|
-
it 'should fetch translations' do
|
133
|
-
translation = WebTranslateIt::Translation.new({ 'locale' => 'en', 'text' => 'Hello' })
|
134
|
-
string = WebTranslateIt::String.new({ 'key' => 'greetings', 'translations' => [translation] })
|
135
|
-
WebTranslateIt::Connection.new(api_key) do
|
136
|
-
string.save
|
137
|
-
string_fetched = WebTranslateIt::String.find(string.id)
|
138
|
-
string_fetched.translation_for('en').should_not be_nil
|
139
|
-
string_fetched.translation_for('en').text.should == 'Hello'
|
140
|
-
string_fetched.translation_for('fr').should be_nil
|
141
|
-
string.delete
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should not return a stale object' do
|
146
|
-
string = WebTranslateIt::String.new({ key: 'greetings 2' })
|
147
|
-
translation = WebTranslateIt::Translation.new({ locale: 'es', text: 'text', string_id: string.id })
|
148
|
-
string.translations << translation
|
149
|
-
string.translation_for('fr').should be_nil
|
150
|
-
string.translation_for('es').should_not be_nil
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WebTranslateIt::Term do
|
4
|
-
let(:api_key) { 'proj_pvt_glzDR250FLXlMgJPZfEyHQ' }
|
5
|
-
|
6
|
-
describe '#initialize' do
|
7
|
-
it 'should assign api_key and many parameters' do
|
8
|
-
term = WebTranslateIt::Term.new({ 'id' => 1234, 'text' => 'bacon' })
|
9
|
-
term.id.should == 1234
|
10
|
-
term.text.should == 'bacon'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should assign parameters using symbols' do
|
14
|
-
term = WebTranslateIt::Term.new({ id: 1234, text: 'bacon' })
|
15
|
-
term.id.should == 1234
|
16
|
-
term.text.should == 'bacon'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#save' do
|
21
|
-
it 'should create a new Term' do
|
22
|
-
WebTranslateIt::Connection.new(api_key) do
|
23
|
-
term = WebTranslateIt::Term.new({ 'text' => 'Term', 'description' => 'A description' })
|
24
|
-
term.save
|
25
|
-
term.id.should_not be_nil
|
26
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
27
|
-
term_fetched.should_not be_nil
|
28
|
-
term_fetched.should be_a(WebTranslateIt::Term)
|
29
|
-
term_fetched.id.should == term.id
|
30
|
-
term.delete
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should update an existing Term' do
|
35
|
-
WebTranslateIt::Connection.new(api_key) do
|
36
|
-
term = WebTranslateIt::Term.new({ 'text' => 'Term 2', 'description' => 'A description' })
|
37
|
-
term.save
|
38
|
-
term.text = 'A Term'
|
39
|
-
term.save
|
40
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
41
|
-
term_fetched.text.should == 'A Term'
|
42
|
-
term.delete
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should create a new Term with a TermTranslation' do
|
47
|
-
translation1 = WebTranslateIt::TermTranslation.new({ 'locale' => 'fr', 'text' => 'Bonjour' })
|
48
|
-
translation2 = WebTranslateIt::TermTranslation.new({ 'locale' => 'fr', 'text' => 'Salut' })
|
49
|
-
|
50
|
-
term = WebTranslateIt::Term.new({ 'text' => 'Hello', 'translations' => [translation1, translation2] })
|
51
|
-
WebTranslateIt::Connection.new(api_key) do
|
52
|
-
term.save
|
53
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
54
|
-
term_fetched.translation_for('fr').should_not be_nil
|
55
|
-
term_fetched.translation_for('fr')[0].text.should == 'Salut'
|
56
|
-
term_fetched.translation_for('fr')[1].text.should == 'Bonjour'
|
57
|
-
term_fetched.translation_for('es').should be_nil
|
58
|
-
term.delete
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should update a Term and save its Translation' do
|
63
|
-
translation1 = WebTranslateIt::TermTranslation.new({ 'locale' => 'fr', 'text' => 'Bonjour' })
|
64
|
-
translation2 = WebTranslateIt::TermTranslation.new({ 'locale' => 'fr', 'text' => 'Salut' })
|
65
|
-
|
66
|
-
term = WebTranslateIt::Term.new({ 'text' => 'Hi!' })
|
67
|
-
WebTranslateIt::Connection.new(api_key) do
|
68
|
-
term.save
|
69
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
70
|
-
term_fetched.translation_for('fr').should be_nil
|
71
|
-
|
72
|
-
term_fetched.translations = [translation1, translation2]
|
73
|
-
term_fetched.save
|
74
|
-
|
75
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
76
|
-
term_fetched.translation_for('fr').should_not be_nil
|
77
|
-
term_fetched.translation_for('fr')[0].text.should == 'Salut'
|
78
|
-
term_fetched.translation_for('fr')[1].text.should == 'Bonjour'
|
79
|
-
term.delete
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe '#delete' do
|
85
|
-
it 'should delete a Term' do
|
86
|
-
term = WebTranslateIt::Term.new({ 'text' => 'bacon' })
|
87
|
-
WebTranslateIt::Connection.new(api_key) do
|
88
|
-
term.save
|
89
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
90
|
-
term_fetched.should_not be_nil
|
91
|
-
|
92
|
-
term_fetched.delete
|
93
|
-
term_fetched = WebTranslateIt::Term.find(term.id)
|
94
|
-
term_fetched.should be_nil
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe '#find_all' do
|
100
|
-
it 'should fetch many terms' do
|
101
|
-
WebTranslateIt::Connection.new(api_key) do
|
102
|
-
terms = WebTranslateIt::Term.find_all
|
103
|
-
count = terms.count
|
104
|
-
|
105
|
-
term1 = WebTranslateIt::Term.new({ 'text' => 'greeting 1' })
|
106
|
-
term1.save
|
107
|
-
term2 = WebTranslateIt::Term.new({ 'text' => 'greeting 2' })
|
108
|
-
term2.save
|
109
|
-
term3 = WebTranslateIt::Term.new({ 'text' => 'greeting 3' })
|
110
|
-
term3.save
|
111
|
-
|
112
|
-
terms = WebTranslateIt::Term.find_all
|
113
|
-
count - terms.count.should == 3
|
114
|
-
|
115
|
-
term1.delete
|
116
|
-
term2.delete
|
117
|
-
term3.delete
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|