web_translate_it 1.7.1.7 → 1.7.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,45 +2,44 @@
2
2
  module WebTranslateIt
3
3
  class CommandLine
4
4
  require 'fileutils'
5
- attr_accessor :configuration, :options, :parameters
6
-
7
- def initialize(command, options, path, parameters)
8
- self.options = options
5
+ attr_accessor :configuration, :global_options, :command_options, :parameters
6
+
7
+ def initialize(command, command_options, global_options, parameters, project_path)
8
+ self.command_options = command_options
9
9
  self.parameters = parameters
10
- if command == 'autoconf'
11
- autoconf
12
- exit
13
- end
14
- self.configuration = WebTranslateIt::Configuration.new(path, options.config)
10
+ self.configuration = WebTranslateIt::Configuration.new(project_path, global_options.config)
15
11
  self.send(command)
16
12
  end
17
13
 
18
14
  def pull
19
15
  STDOUT.sync = true
16
+ `#{configuration.before_pull}` if configuration.before_pull
20
17
  fetch_locales_to_pull.each do |locale|
21
18
  configuration.files.find_all{ |file| file.locale == locale }.each do |file|
22
19
  print "Pulling #{file.file_path}... "
23
- puts file.fetch(ARGV.index('--force'))
20
+ puts file.fetch(command_options.force)
24
21
  end
25
22
  end
23
+ `#{configuration.after_pull}` if configuration.after_pull
26
24
  end
27
25
 
28
26
  def push
29
27
  STDOUT.sync = true
28
+ `#{configuration.before_push}` if configuration.before_push
30
29
  fetch_locales_to_push(configuration).each do |locale|
31
- merge = !(ARGV.index('--merge')).nil?
32
- ignore_missing = !(ARGV.index('--ignore_missing')).nil?
33
30
  configuration.files.find_all{ |file| file.locale == locale }.each do |file|
34
31
  print "Pushing #{file.file_path}... "
35
- puts file.upload(merge, ignore_missing, options.label, options.low_priority)
32
+ puts file.upload(command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority)
36
33
  end
37
34
  end
35
+ `#{configuration.after_push}` if configuration.after_push
38
36
  end
39
37
 
40
38
  def add
41
39
  STDOUT.sync = true
42
- if parameters.nil?
43
- puts "Usage: wti add file1 file2"
40
+ if parameters == []
41
+ puts "No master file given."
42
+ puts "Usage: wti add master_file1 master_file2 ..."
44
43
  exit
45
44
  end
46
45
  parameters.each do |param|
@@ -48,12 +47,13 @@ module WebTranslateIt
48
47
  print "Creating #{file.file_path}... "
49
48
  puts file.create
50
49
  end
51
- puts "Master file added. Use `wti push --all` to send your existing translations."
50
+ puts "Master file added."
52
51
  end
53
52
 
54
53
  def addlocale
55
54
  STDOUT.sync = true
56
- if parameters.nil?
55
+ if parameters == []
56
+ puts "No locale code given."
57
57
  puts "Usage: wti addlocale locale1 locale2 ..."
58
58
  exit
59
59
  end
@@ -65,9 +65,19 @@ module WebTranslateIt
65
65
  end
66
66
 
67
67
  def autoconf
68
- puts "We will attempt to configure your project automagically"
69
- api_key = Util.ask("Please enter your project API Key")
70
- path = Util.ask("Where should we create the configuration file?", 'config/translation.yml')
68
+ puts ""
69
+ puts "============================================"
70
+ puts " Warning: `wti autoconf` will be deprecated."
71
+ puts " Please use `wti init` instead."
72
+ puts "============================================"
73
+ puts ""
74
+ init
75
+ end
76
+
77
+ def init
78
+ puts "This command configures your project."
79
+ api_key = Util.ask("Enter your project API Key:")
80
+ path = Util.ask("Where should we put the configuration file?", 'config/translation.yml')
71
81
  FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/'))
72
82
  project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
73
83
  project_info = project['project']
@@ -75,13 +85,13 @@ module WebTranslateIt
75
85
  error = false
76
86
  project_info['project_files'].each do |file|
77
87
  if file['name'].nil? or file['name'].strip == ''
78
- puts "Project File #{file['id']} doesn’t seem to be set up."
88
+ puts "Project File #{file['id']} doesn’t seem to be set up.".failure
79
89
  error = true
80
90
  elsif !File.exists?(file['name'])
81
- puts "Could not find file `#{file['name']}`."
91
+ puts "Could not find file `#{file['name']}`.".failure
82
92
  error = true
83
93
  else
84
- puts "Found #{file['name']}."
94
+ puts "Found #{file['name']}.".success
85
95
  end
86
96
  end
87
97
  if error
@@ -95,6 +105,16 @@ module WebTranslateIt
95
105
  end
96
106
 
97
107
  def stats
108
+ puts ""
109
+ puts "============================================="
110
+ puts " Warning: `wti stats` will be deprecated."
111
+ puts " Please use `wti status` or `wti st` instead."
112
+ puts "============================================="
113
+ puts ""
114
+ status
115
+ end
116
+
117
+ def status
98
118
  stats = YAML.load(Project.fetch_stats(configuration.api_key))
99
119
  stale = false
100
120
  stats.each do |locale, values|
@@ -104,12 +124,14 @@ module WebTranslateIt
104
124
  stale = true if values['stale']
105
125
  end
106
126
  if stale
107
- self.stats if Util.ask_yes_no("Some statistics displayed above are stale. Would you like to refresh?", true)
127
+ self.status if Util.ask_yes_no("Some of these stats are stale. Would you like to refresh?", true)
108
128
  end
109
129
  end
110
130
 
131
+ alias :st :status
132
+
111
133
  def server
112
- WebTranslateIt::Server.start(options.host, options.port)
134
+ WebTranslateIt::Server.start(command_options.host, command_options.port)
113
135
  end
114
136
 
115
137
  def method_missing(m, *args, &block)
@@ -117,23 +139,23 @@ module WebTranslateIt
117
139
  end
118
140
 
119
141
  def fetch_locales_to_pull
120
- if options.locale
121
- locales = [Util.sanitize_locale(options.locale)]
142
+ if command_options.locale
143
+ locales = command_options.locale.split.map{ |locale| Util.sanitize_locale(locale) }
122
144
  else
123
145
  locales = configuration.target_locales
124
146
  configuration.ignore_locales.each{ |locale_to_delete| locales.delete(locale_to_delete) }
125
147
  end
126
- locales.push(configuration.source_locale) if options.all
148
+ locales.push(configuration.source_locale) if command_options.all
127
149
  return locales.uniq
128
150
  end
129
151
 
130
152
  def fetch_locales_to_push(configuration)
131
- if options.locale
132
- locales = [Util.sanitize_locale(options.locale)]
153
+ if command_options.locale
154
+ locales = command_options.locale.split.map{ |locale| Util.sanitize_locale(locale) }
133
155
  else
134
156
  locales = [configuration.source_locale]
135
157
  end
136
- locales += configuration.target_locales if options.all
158
+ locales += configuration.target_locales if command_options.all
137
159
  return locales.uniq
138
160
  end
139
161
 
@@ -145,12 +167,15 @@ api_key: #{api_key}
145
167
  # eg. [:en, :fr] or just 'en'
146
168
  # ignore_locales: '#{project_info["source_locale"]["code"]}'
147
169
 
148
- # Optional, only used by wti server
170
+ # Optional
149
171
  # before_pull: "echo 'some unix command'" # Command executed before pulling files
150
172
  # after_pull: "touch tmp/restart.txt" # Command executed after pulling files
173
+ #
174
+ # before_push: "echo 'some unix command'" # Command executed before pushing files
175
+ # after_push: "touch tmp/restart.txt" # Command executed after pushing files
151
176
 
152
177
  FILE
153
178
  return file
154
- end
179
+ end
155
180
  end
156
181
  end
@@ -10,7 +10,7 @@ module WebTranslateIt
10
10
  class Configuration
11
11
  require 'yaml'
12
12
  require 'fileutils'
13
- attr_accessor :path, :api_key, :source_locale, :target_locales, :files, :ignore_locales, :logger, :before_pull, :after_pull
13
+ attr_accessor :path, :api_key, :source_locale, :target_locales, :files, :ignore_locales, :logger, :before_pull, :after_pull, :before_push, :after_push
14
14
 
15
15
  # Load configuration file from the path.
16
16
  def initialize(root_path = Rails.root, path_to_config_file = "config/translation.yml")
@@ -20,6 +20,8 @@ module WebTranslateIt
20
20
  self.api_key = configuration['api_key']
21
21
  self.before_pull = configuration['before_pull']
22
22
  self.after_pull = configuration['after_pull']
23
+ self.before_push = configuration['before_push']
24
+ self.after_push = configuration['after_push']
23
25
  project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
24
26
  set_locales_to_ignore(configuration)
25
27
  set_files(project_info['project'])
@@ -36,18 +36,12 @@ module WebTranslateIt
36
36
  end
37
37
 
38
38
  post '/pull/' do
39
- @config = WebTranslateIt::Configuration.new('.')
40
- `#{config.before_pull}` if config.before_pull
41
39
  `wti pull`
42
- `#{config.after_pull}` if config.after_pull
43
40
  redirect "/"
44
41
  end
45
42
 
46
43
  post '/pull/:locale' do
47
- @config = WebTranslateIt::Configuration.new('.')
48
- `#{config.before_pull}` if config.before_pull
49
44
  `wti pull -l #{params[:locale]}`
50
- `#{config.after_pull}` if config.after_pull
51
45
  redirect "/#{params[:locale]}"
52
46
  end
53
47
 
@@ -46,16 +46,16 @@ module WebTranslateIt
46
46
  File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
47
47
  Util.handle_response(response)
48
48
  rescue
49
- "\n/!\\ An error occured: #{$!}"
49
+ "\n/!\\ An error occured: #{$!}".failure
50
50
  end
51
51
  end
52
52
  rescue Timeout::Error
53
- puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
53
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds.".failure
54
54
  sleep(5)
55
55
  fetch(force)
56
56
  end
57
57
  else
58
- return "Not needed"
58
+ return "Not needed".success
59
59
  end
60
60
  end
61
61
 
@@ -79,13 +79,13 @@ module WebTranslateIt
79
79
  Util.handle_response(http.request(request))
80
80
  end
81
81
  rescue Timeout::Error
82
- puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
82
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds.".failure
83
83
  sleep(5)
84
84
  upload(merge, ignore_missing)
85
85
  end
86
86
  end
87
87
  else
88
- puts "\nFile #{self.file_path} doesn't exist."
88
+ puts "\nFile #{self.file_path} doesn't exist.".failure
89
89
  end
90
90
  end
91
91
 
@@ -109,13 +109,13 @@ module WebTranslateIt
109
109
  Util.handle_response(http.request(request))
110
110
  end
111
111
  rescue Timeout::Error
112
- puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
112
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds.".failure
113
113
  sleep(5)
114
114
  create
115
115
  end
116
116
  end
117
117
  else
118
- puts "\nFile #{self.file_path} doesn't exist!"
118
+ puts "\nFile #{self.file_path} doesn't exist!".failure
119
119
  end
120
120
  end
121
121
 
@@ -41,20 +41,20 @@ module WebTranslateIt
41
41
  end
42
42
 
43
43
  def self.welcome_message
44
- puts "Web Translate It v#{WebTranslateIt::Util.version}"
44
+ puts "Web Translate It v#{version}"
45
45
  end
46
46
 
47
47
  def self.handle_response(response, return_response = false)
48
48
  if response.code.to_i >= 400 and response.code.to_i < 500
49
- "We had a problem connecting to Web Translate It with this API key. Make sure it is correct."
49
+ "Can't fetch project with this API key. Make sure it is correct.".failure
50
50
  elsif response.code.to_i >= 500
51
- "Web Translate It is temporarily unavailable and has been notified of this issue. Please try again shortly."
51
+ "Web Translate It is temporarily unavailable. We've been notified of this issue. Please try again shortly.".failure
52
52
  else
53
53
  return response.body if return_response
54
- return "200 OK" if response.code.to_i == 200
55
- return "201 Created" if response.code.to_i == 201
56
- return "202 Accepted" if response.code.to_i == 202
57
- return "304 Not Modified" if response.code.to_i == 304
54
+ return "200 OK".success if response.code.to_i == 200
55
+ return "201 Created".success if response.code.to_i == 201
56
+ return "202 Accepted".success if response.code.to_i == 202
57
+ return "304 Not Modified".success if response.code.to_i == 304
58
58
  end
59
59
  end
60
60
 
@@ -134,7 +134,24 @@ module WebTranslateIt
134
134
 
135
135
  def self.sanitize_locale(locale)
136
136
  locale.gsub('_', '-')
137
- end
138
-
137
+ end
138
+ end
139
+ end
140
+
141
+ class String
142
+ require 'rainbow'
143
+
144
+ ##
145
+ # Green foreground for success
146
+
147
+ def success
148
+ self.foreground(:green)
149
+ end
150
+
151
+ ##
152
+ # Red foreground for failure
153
+
154
+ def failure
155
+ self.background(:red).foreground(:white)
139
156
  end
140
157
  end
data/man/wti.1 CHANGED
@@ -1,10 +1,10 @@
1
- .\" generated with Ronn/v0.4.1
2
- .\" http://github.com/rtomayko/ronn/
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "WTI" "1" "March 2010" "Atelier Convivialité" "Web Translate It"
4
+ .TH "WTI" "1" "March 2011" "Atelier Convivialité" "Web Translate It"
5
5
  .
6
6
  .SH "NAME"
7
- \fBwti\fR \-\- WebTranslateIt.com from the command line
7
+ \fBwti\fR \- WebTranslateIt\.com from the command line
8
8
  .
9
9
  .SH "SYNOPSIS"
10
10
  \fBwti\fR \fICOMMAND\fR \fIOPTIONS\fR
@@ -16,66 +16,63 @@
16
16
  \fBwti pull\fR [\fB\-l\fR] \fIOPTIONS\fR
17
17
  .
18
18
  .SH "DESCRIPTION"
19
- \fBwti\fR is an utility to help you sync language files between the
20
- WebTranslateIt.com service and your computer/server.
19
+ \fBwti\fR is an utility to help you sync language files between the WebTranslateIt\.com service and your computer/server\.
21
20
  .
22
21
  .P
23
- \fBwti push\fR will push your master language file to Web Translate It. It means it will
24
- update the strings hosted at Web Translate It by the strings from the file you push.
22
+ \fBwti push\fR will push your master language file to Web Translate It\. It means it will update the strings hosted at Web Translate It by the strings from the file you push\.
25
23
  .
26
24
  .P
27
- \fBwti pull\fR will pull the target language files from Web Translate It. It will download
28
- and update your file with the latest translations from Web Translate It.
25
+ \fBwti pull\fR will pull the target language files from Web Translate It\. It will download and update your file with the latest translations from Web Translate It\.
29
26
  .
30
27
  .P
31
- \fBwti stats\fR fetch and display translation statistics from Web Translate It.
28
+ \fBwti status\fR fetch and display translation statistics from Web Translate It\.
32
29
  .
33
30
  .SH "OPTIONS"
34
- \fBwti\fR's default mode of operation is to push only the master language file and to only
35
- pull target language files.
31
+ \fBwti\fR\'s default mode of operation is to push only the master language file and to only pull target language files\.
36
32
  .
37
33
  .P
38
34
  These options can be used to change this behaviour:
39
35
  .
40
36
  .TP
41
37
  \fB\-\-all\fR
42
- Push or pull all. For example, \fBwti push \-\-all\fR will push master and target language files. \fBwti pull \-\-all\fR will pull master and target language files
38
+ Push or pull all\. For example, \fBwti push \-\-all\fR will push master and target language files\. \fBwti pull \-\-all\fR will pull master and target language files
43
39
  .
44
40
  .TP
45
41
  \fB\-l\fR, \fB\-\-locale\fR
46
- Set the locale to push or pull explicitly. For example \fBwti pull \-l fr\fR will only pull
47
- the French language file.
42
+ Set the locale to push or pull explicitly\. For example \fBwti pull \-l fr\fR will only pull the French language file\.
48
43
  .
49
44
  .TP
50
45
  \fB\-\-force\fR
51
- The Web Translate It API use HTTP caching to be efficient, and check if your file needs
52
- to be updated by checking its modification date against the project’s latest activity.
53
- Use this option to bypass this check.
46
+ The Web Translate It API use HTTP caching to be efficient, and check if your file needs to be updated by checking its modification date against the project’s latest activity\. Use this option to bypass this check\.
54
47
  .
55
48
  .P
56
49
  You may additionally ask for help:
57
50
  .
58
51
  .TP
59
52
  \fB\-h\fR, \fB\-\-help\fR
60
- Print help.
53
+ Print help\.
61
54
  .
62
55
  .SH "CONFIGURATION"
63
- The first \fBwti\fR is used on a project, it must be configured.
56
+ The first \fBwti\fR is used on a project, it must be configured\.
64
57
  .
65
58
  .P
66
- \fBwti autoconf\fR will help you create a configuration file to sync with
67
- Web Translate It.
59
+ \fBwti init\fR will help you create a configuration file to sync with Web Translate It\.
68
60
  .
69
61
  .SH "EXAMPLES"
70
62
  .
71
63
  .nf
64
+
72
65
  $ wti push
73
- Pushing ./config/locales/app/en.yml…
74
- Pushing ./config/locales/defaults/en.yml…
66
+ Pushing \./config/locales/app/en\.yml…
67
+ Pushing \./config/locales/defaults/en\.yml…
68
+
69
+
75
70
  $ wti pull \-l fr
76
- Pulling ./config/locales/app/fr.yml…
77
- Pulling ./config/locales/defaults/fr.yml…
78
- $ wti stats
71
+ Pulling \./config/locales/app/fr\.yml…
72
+ Pulling \./config/locales/defaults/fr\.yml…
73
+
74
+
75
+ $ wti status
79
76
  fr: 100% translated, 90% completed
80
77
  ru: 10% translated, 10% completed
81
78
  pt_BR: 0% translated, 0% completed
@@ -84,7 +81,7 @@ en: 100% translated, 90% completed
84
81
  .fi
85
82
  .
86
83
  .SH "BUGS"
87
- \fIhttp://github.com/atelierConvivialite/webtranslateit/issues\fR
84
+ \fIhttp://github\.com/atelierConvivialite/webtranslateit/issues\fR
88
85
  .
89
86
  .SH "AUTHOR"
90
- Édouard Brière :: edouard@atelierconvivialite.com
87
+ Édouard Brière :: edouard@atelierconvivialite\.com