web_translate_it 1.6.4 → 1.6.5
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/examples/en.yml +3 -0
- data/history.md +6 -0
- data/lib/web_translate_it/command_line.rb +11 -11
- data/lib/web_translate_it/translation_file.rb +8 -4
- data/lib/web_translate_it/util.rb +73 -4
- data/spec/web_translate_it/configuration_spec.rb +16 -20
- data/spec/web_translate_it/translation_file_spec.rb +12 -11
- data/spec/web_translate_it_spec.rb +0 -1
- data/version.yml +1 -1
- metadata +6 -5
data/examples/en.yml
ADDED
data/history.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## Version 1.6.5 /2010-04-19
|
2
|
+
|
3
|
+
* Enhancement: Remove new line on push/pull result. It now displays `Pulling config/locales/app/fr.yml… 200 OK`.
|
4
|
+
* Enhancement: `wti stats` now propose to refresh the stats if the stats displayed are stale.
|
5
|
+
* Bug fix: `wti push` used to crash on non-existent files. Close #24.
|
6
|
+
|
1
7
|
## Version 1.6.4 /2010-04-02
|
2
8
|
|
3
9
|
* Bug fix: Rake tasks not working
|
@@ -44,20 +44,22 @@ OPTION
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.pull
|
47
|
+
STDOUT.sync = true
|
47
48
|
configuration = fetch_configuration
|
48
49
|
fetch_locales_to_pull(configuration).each do |locale|
|
49
50
|
configuration.files.find_all{ |file| file.locale == locale }.each do |file|
|
50
|
-
|
51
|
+
print "Pulling #{file.file_path}… "
|
51
52
|
puts file.fetch(ARGV.index('--force'))
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
57
|
def self.push
|
58
|
+
STDOUT.sync = true
|
57
59
|
configuration = fetch_configuration
|
58
60
|
fetch_locales_to_push(configuration).each do |locale|
|
59
61
|
configuration.files.find_all{ |file| file.locale == locale }.each do |file|
|
60
|
-
|
62
|
+
print "Pushing #{file.file_path}… "
|
61
63
|
puts file.upload
|
62
64
|
end
|
63
65
|
end
|
@@ -65,15 +67,8 @@ OPTION
|
|
65
67
|
|
66
68
|
def self.autoconf
|
67
69
|
puts "We will attempt to configure your project automagically"
|
68
|
-
|
69
|
-
|
70
|
-
if api_key == ""
|
71
|
-
puts "You must enter your project API key provided by Web Translate It"
|
72
|
-
exit
|
73
|
-
end
|
74
|
-
puts "Where should we create the configuration file? (Default: `config/translation.yml`)"
|
75
|
-
path = STDIN.gets.strip
|
76
|
-
path = "config/translation.yml" if path == ""
|
70
|
+
api_key = Util.ask("Please enter your project API Key")
|
71
|
+
path = Util.ask("Where should we create the configuration file?", 'config/translation.yml')
|
77
72
|
FileUtils.mkpath(path.split('/')[0..path.split('/').size-1])
|
78
73
|
project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
79
74
|
project_info = project['project']
|
@@ -103,10 +98,15 @@ OPTION
|
|
103
98
|
def self.stats
|
104
99
|
configuration = fetch_configuration
|
105
100
|
stats = YAML.load(Project.fetch_stats(configuration.api_key))
|
101
|
+
stale = false
|
106
102
|
stats.each do |locale, values|
|
107
103
|
percent_translated = Util.calculate_percentage(values['count_strings_to_proofread'] + values['count_strings_done'] + values['count_strings_to_verify'], values['count_strings'])
|
108
104
|
percent_completed = Util.calculate_percentage(values['count_strings_done'], values['count_strings'])
|
109
105
|
puts "#{locale}: #{percent_translated}% translated, #{percent_completed}% completed #{values['stale'] ? "Stale" : ""}"
|
106
|
+
stale = true if values['stale']
|
107
|
+
end
|
108
|
+
if stale
|
109
|
+
CommandLine.stats if Util.ask_yes_no("Some statistics displayed above are stale. Would you like to refresh?", true)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -57,11 +57,15 @@ module WebTranslateIt
|
|
57
57
|
# actually takes place.
|
58
58
|
# This is due to the fact that language file imports are handled by background processing.
|
59
59
|
def upload
|
60
|
-
File.
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
if File.exists?(self.file_path)
|
61
|
+
File.open(self.file_path) do |file|
|
62
|
+
WebTranslateIt::Util.http_connection do |http|
|
63
|
+
request = Net::HTTP::Put::Multipart.new(api_url, "file" => UploadIO.new(file, "text/plain", file.path))
|
64
|
+
Util.handle_response(http.request(request))
|
65
|
+
end
|
64
66
|
end
|
67
|
+
else
|
68
|
+
puts "\nFile #{self.file_path} doesn't exist!"
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
@@ -39,14 +39,83 @@ module WebTranslateIt
|
|
39
39
|
if response.code.to_i >= 400 and response.code.to_i < 500
|
40
40
|
"We had a problem connecting to Web Translate It with this API key. Make sure it is correct."
|
41
41
|
elsif response.code.to_i >= 500
|
42
|
-
"Web Translate It is temporarily unavailable. Please try again shortly."
|
42
|
+
"Web Translate It is temporarily unavailable and has been notified of this issue. Please try again shortly."
|
43
43
|
else
|
44
|
-
if return_response
|
45
|
-
|
44
|
+
return response.body if return_response
|
45
|
+
return "200 OK" if response.code.to_i == 200
|
46
|
+
return "304 Not Modified" if response.code.to_i == 304
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Ask a question. Returns a true for yes, false for no, default for nil.
|
52
|
+
|
53
|
+
def self.ask_yes_no(question, default=nil)
|
54
|
+
qstr = case default
|
55
|
+
when nil
|
56
|
+
'yn'
|
57
|
+
when true
|
58
|
+
'Yn'
|
59
|
+
else
|
60
|
+
'yN'
|
61
|
+
end
|
62
|
+
|
63
|
+
result = nil
|
64
|
+
|
65
|
+
while result.nil?
|
66
|
+
result = ask("#{question} [#{qstr}]")
|
67
|
+
result = case result
|
68
|
+
when /^[Yy].*/
|
69
|
+
true
|
70
|
+
when /^[Nn].*/
|
71
|
+
false
|
72
|
+
when /^$/
|
73
|
+
when nil
|
74
|
+
default
|
46
75
|
else
|
47
|
-
|
76
|
+
nil
|
48
77
|
end
|
49
78
|
end
|
79
|
+
|
80
|
+
return result
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Ask a question. Returns an answer.
|
85
|
+
|
86
|
+
def self.ask(question, default=nil)
|
87
|
+
question = question + " (Default: #{default})" unless default.nil?
|
88
|
+
print(question + " ")
|
89
|
+
STDOUT.flush
|
90
|
+
|
91
|
+
result = STDIN.gets
|
92
|
+
result.chomp! if result
|
93
|
+
result = default if result.nil? or result == ''
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Choose from a list of options. +question+ is a prompt displayed above
|
99
|
+
# the list. +list+ is a list of option strings. Returns the pair
|
100
|
+
# [option_name, option_index].
|
101
|
+
|
102
|
+
def self.choose_from_list(question, list)
|
103
|
+
STDOUT.puts question
|
104
|
+
|
105
|
+
list.each_with_index do |item, index|
|
106
|
+
STDOUT.puts " #{index+1}. #{item}"
|
107
|
+
end
|
108
|
+
|
109
|
+
STDOUT.print "> "
|
110
|
+
STDOUT.flush
|
111
|
+
|
112
|
+
result = STDIN.gets
|
113
|
+
|
114
|
+
return nil, nil unless result
|
115
|
+
|
116
|
+
result = result.strip.to_i - 1
|
117
|
+
return list[result], result
|
50
118
|
end
|
119
|
+
|
51
120
|
end
|
52
121
|
end
|
@@ -2,9 +2,10 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
|
2
2
|
|
3
3
|
describe WebTranslateIt::Configuration do
|
4
4
|
describe "#initialize" do
|
5
|
+
subject { WebTranslateIt::Configuration::Rails = OpenStruct.new(:root => Pathname.new(File.dirname(__FILE__) + "/../examples")) }
|
6
|
+
|
5
7
|
it "should fetch and not blow up" do
|
6
|
-
WebTranslateIt::Configuration
|
7
|
-
lambda{ WebTranslateIt::Configuration.new }.should_not raise_error
|
8
|
+
expect{ WebTranslateIt::Configuration.new }.to_not raise_error
|
8
9
|
end
|
9
10
|
|
10
11
|
it "should load the content of the YAML file" do
|
@@ -15,9 +16,8 @@ describe WebTranslateIt::Configuration do
|
|
15
16
|
YAML.should_receive(:load_file).and_return(config_hash)
|
16
17
|
WebTranslateIt::Configuration.new(File.dirname(__FILE__) + '/../..', 'examples/translation.yml')
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
it "should assign the API key, files" do
|
20
|
-
WebTranslateIt::Configuration::Rails = OpenStruct.new(:root => Pathname.new(File.dirname(__FILE__) + "/../examples"))
|
21
21
|
configuration = WebTranslateIt::Configuration.new
|
22
22
|
configuration.api_key.should == '4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2'
|
23
23
|
configuration.files.first.should be_a(WebTranslateIt::TranslationFile)
|
@@ -25,40 +25,36 @@ describe WebTranslateIt::Configuration do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#set_locales_to_ignore" do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
28
|
+
let(:configuration) { WebTranslateIt::Configuration.new }
|
29
|
+
subject { WebTranslateIt::Configuration::Rails = OpenStruct.new(:root => Pathname.new(File.dirname(__FILE__) + "/../examples")) }
|
30
|
+
|
33
31
|
it "should return an array" do
|
34
32
|
config_hash = { 'ignore_locales' => 'en' }
|
35
|
-
|
33
|
+
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
36
34
|
end
|
37
35
|
|
38
36
|
it "should not blow up if no locales are given" do
|
39
37
|
config_hash = { 'ignore_locales' => nil }
|
40
|
-
|
41
|
-
|
38
|
+
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
39
|
+
configuration.set_locales_to_ignore(config_hash).should == []
|
42
40
|
end
|
43
41
|
|
44
42
|
it "should return an array of 2 elements if given array of strings" do
|
45
43
|
config_hash = { 'ignore_locales' => ['en', 'fr'] }
|
46
|
-
|
47
|
-
|
44
|
+
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
45
|
+
configuration.set_locales_to_ignore(config_hash).should == ['en', 'fr']
|
48
46
|
end
|
49
47
|
|
50
48
|
it "should return an array of 1 element if given a symbol" do
|
51
49
|
config_hash = { 'ignore_locales' => :en }
|
52
|
-
|
53
|
-
|
50
|
+
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
51
|
+
configuration.set_locales_to_ignore(config_hash).should == ['en']
|
54
52
|
end
|
55
53
|
|
56
54
|
it "should return an array of 2 element if given an array of symbol and string" do
|
57
55
|
config_hash = { 'ignore_locales' => [:en, 'fr'] }
|
58
|
-
|
59
|
-
|
56
|
+
configuration.set_locales_to_ignore(config_hash).should be_a(Array)
|
57
|
+
configuration.set_locales_to_ignore(config_hash).should == ['en', 'fr']
|
60
58
|
end
|
61
|
-
|
62
59
|
end
|
63
|
-
|
64
60
|
end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
3
|
describe WebTranslateIt::TranslationFile do
|
4
|
-
before(:each) do
|
5
|
-
@translation_file = WebTranslateIt::TranslationFile.new(2267, "examples/en.yml", 'fr', "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2")
|
6
|
-
end
|
7
4
|
|
8
5
|
describe "#initialize" do
|
9
6
|
it "should assign id, file_path and api_key" do
|
@@ -15,44 +12,48 @@ describe WebTranslateIt::TranslationFile do
|
|
15
12
|
end
|
16
13
|
|
17
14
|
describe "#fetch" do
|
15
|
+
let(:translation_file) { WebTranslateIt::TranslationFile.new(2267, "examples/en.yml", 'fr', "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2") }
|
16
|
+
|
18
17
|
it "should prepare a HTTP request and get a 200 OK if the language file is stale" do
|
19
18
|
file = mock(File)
|
20
19
|
file.stub(:puts => true, :close => true)
|
21
20
|
File.stub(:exist? => true, :mtime => Time.at(0), :new => file)
|
22
|
-
|
21
|
+
translation_file.fetch.should == "200 OK"
|
23
22
|
end
|
24
23
|
|
25
24
|
it "should prepare a HTTP request and get a 200 OK if the language file is stale using the force download parameter" do
|
26
25
|
file = mock(File)
|
27
26
|
file.stub(:puts => true, :close => true)
|
28
27
|
File.stub(:exist? => true, :mtime => Time.at(0), :new => file)
|
29
|
-
|
28
|
+
translation_file.fetch(true).should == "200 OK"
|
30
29
|
end
|
31
30
|
|
32
31
|
it "should prepare a HTTP request and get a 304 OK if the language file is fresh" do
|
33
32
|
file = mock(File)
|
34
33
|
file.stub(:puts => true, :close => true)
|
35
34
|
File.stub(:exist? => true, :mtime => Time.now, :new => file)
|
36
|
-
|
35
|
+
translation_file.fetch.should == "304 Not Modified"
|
37
36
|
end
|
38
37
|
|
39
38
|
it "should prepare a HTTP request and get a 200 OK if the language file is fresh using the force download parameter" do
|
40
39
|
file = mock(File)
|
41
40
|
file.stub(:puts => true, :close => true)
|
42
41
|
File.stub(:exist? => true, :mtime => Time.now, :new => file)
|
43
|
-
|
42
|
+
translation_file.fetch(true).should == "200 OK"
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
46
|
describe "#upload" do
|
47
|
+
let(:translation_file) { WebTranslateIt::TranslationFile.new(2267, "examples/en.yml", 'fr', "4af21ce1fb3a4f7127a60b31ebc41c1446b38bb2") }
|
48
|
+
|
48
49
|
it "should prepare a HTTP request and get a 200 OK" do
|
49
|
-
|
50
|
-
|
50
|
+
translation_file.stub(:file_path => File.join(File.dirname(__FILE__), '..', 'examples', 'en.yml'))
|
51
|
+
translation_file.upload
|
51
52
|
end
|
52
53
|
|
53
54
|
it "should fail if the file does not exist" do
|
54
|
-
|
55
|
-
|
55
|
+
translation_file.stub(:file_path => File.join('something', 'that', 'does', 'not', 'exist'))
|
56
|
+
expect { @translation_file.upload }.to raise_error
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
data/version.yml
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 1.6.
|
8
|
+
- 5
|
9
|
+
version: 1.6.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "\xC3\x89douard Bri\xC3\xA8re"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-19 00:00:00 +02:00
|
18
18
|
default_executable: wti
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -40,8 +40,8 @@ dependencies:
|
|
40
40
|
segments:
|
41
41
|
- 1
|
42
42
|
- 2
|
43
|
-
-
|
44
|
-
version: 1.2.
|
43
|
+
- 9
|
44
|
+
version: 1.2.9
|
45
45
|
type: :development
|
46
46
|
version_requirements: *id002
|
47
47
|
description: A rack middleware and a handful of rake tasks to sync your translations between webtranslateit.com and your rails applications.
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- MIT-LICENSE
|
59
59
|
- README.md
|
60
60
|
- version.yml
|
61
|
+
- examples/en.yml
|
61
62
|
- examples/locale.rb
|
62
63
|
- examples/translation.yml
|
63
64
|
- lib/web_translate_it/auto_fetch.rb
|