web_translate_it 1.8.1.9 → 1.8.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wti CHANGED
@@ -26,7 +26,6 @@ See `wti <command> --help` for more information on a specific command.
26
26
  [options] are:
27
27
  EOS
28
28
  version "Web Translate It v#{WebTranslateIt::Util.version}"
29
- opt :config, "Path to a translation.yml file", :short => "-c", :default => "config/translation.yml"
30
29
  end
31
30
 
32
31
  command = ARGV.shift # get the subcommand
@@ -13,7 +13,7 @@ class WebtranslateitGenerator < Rails::Generator::Base
13
13
  record do |m|
14
14
  if options[:api_key]
15
15
  project_details = YAML.load WebTranslateIt::Project.fetch_info(options[:api_key])
16
- m.template 'translation.yml', 'config/translation.yml',
16
+ m.template '.wti', '.wti',
17
17
  :assigns => { :api_key => options[:api_key], :project => project_details["project"] }
18
18
  m.append_to 'Rakefile', "require 'web_translate_it' rescue LoadError"
19
19
  end
data/history.md CHANGED
@@ -1,8 +1,15 @@
1
- ## Version 1.8.1.9 / 2011-07-29
1
+ ## Version 1.8.2.0 / 2011-09-12
2
+
3
+ * `wti pull` downloads files in parallel, using up to 20 threads.
4
+ This makes syncing much faster for projects containing many files (up to 65 files/sec).
5
+ * Default configuration file was renamed `.wti`. #67.
6
+ The upgrade process should be seamless. Config file will be renamed if a `config/translation.yml` file is detected.
7
+
8
+ ## Version 1.8.1.9 / 2011-09-07
2
9
 
3
10
  * Possible fix for encoding issue in .gemspec file, #66
4
- * Removed dependancy on ansi gem, so wti can now install smoothly on Windows machines.
5
- Windows users had to manually install an extra `win32console` gem. #62.
11
+ * Removed dependency on `ansi` gem, so wti now installs smoothly on Windows machines.
12
+ Prior to that Windows users had to manually install the `win32console` gem. #62.
6
13
 
7
14
  ## Version 1.8.1.8 / 2011-07-29
8
15
 
@@ -12,16 +19,16 @@
12
19
 
13
20
  ## Version 1.8.1.7 / 2011-07-29
14
21
 
15
- * Add dependancy on `win32console` for Microsoft Windows users.
22
+ * Add dependency on `win32console` for Microsoft Windows users.
16
23
 
17
24
  ## Version 1.8.1.6 / 2011-07-25
18
25
 
19
- * Update multipart-post dependancy.
26
+ * Update multipart-post dependency.
20
27
  * Only include CA cert of WTI’s SSL certificate issuer. #61.
21
28
 
22
29
  ## Version 1.8.1.5 / 2011-07-19
23
30
 
24
- * Update ansi dependancy.
31
+ * Update ansi dependency.
25
32
  * Bug fix: re-recreate http connection from scratch after SSL certificate verification failure.
26
33
 
27
34
  ## Version 1.8.1.4 / 2011-06-29
@@ -7,28 +7,48 @@ module WebTranslateIt
7
7
  def initialize(command, command_options, global_options, parameters, project_path)
8
8
  self.command_options = command_options
9
9
  self.parameters = parameters
10
- self.configuration = WebTranslateIt::Configuration.new(project_path, global_options.config) unless command == 'init'
10
+ unless command == 'init'
11
+ self.configuration = WebTranslateIt::Configuration.new(project_path, configuration_file_path)
12
+ end
11
13
  self.send(command)
12
14
  end
13
15
 
14
16
  def pull
15
17
  STDOUT.sync = true
16
18
  `#{configuration.before_pull}` if configuration.before_pull
17
- puts "Pulling files ".titleize
18
- WebTranslateIt::Util.http_connection do |http|
19
- fetch_locales_to_pull.each do |locale|
20
- configuration.files.find_all{ |file| file.locale == locale }.each do |file|
21
- file.fetch(http, command_options.force)
19
+ puts "Pulling files".titleize
20
+
21
+ # Selecting files to pull
22
+ files = []
23
+ fetch_locales_to_pull.each do |locale|
24
+ files.concat configuration.files.find_all{ |file| file.locale == locale }
25
+ end
26
+ # Now actually pulling files
27
+ time = Time.now
28
+ threads = []
29
+ n_threads = (files.count.to_f/3).ceil >= 20 ? 20 : (files.count.to_f/3).ceil
30
+ puts "Using up to #{n_threads} threads"
31
+ files.chunk(n_threads).each do |file_array|
32
+ unless file_array.empty?
33
+ threads << Thread.new(file_array) do |file_array|
34
+ WebTranslateIt::Util.http_connection do |http|
35
+ file_array.each do |file|
36
+ file.fetch(http, command_options.force)
37
+ end
38
+ end
22
39
  end
23
40
  end
24
41
  end
42
+ threads.each { |thread| thread.join }
43
+ time = Time.now - time
44
+ puts "Pulled #{files.count} files in #{time} seconds at #{files.count/time} files/sec."
25
45
  `#{configuration.after_pull}` if configuration.after_pull
26
46
  end
27
47
 
28
48
  def push
29
49
  STDOUT.sync = true
30
50
  `#{configuration.before_push}` if configuration.before_push
31
- puts "Pushing files ".titleize
51
+ puts "Pushing files".titleize
32
52
  WebTranslateIt::Util.http_connection do |http|
33
53
  fetch_locales_to_push(configuration).each do |locale|
34
54
  configuration.files.find_all{ |file| file.locale == locale }.each do |file|
@@ -71,15 +91,13 @@ module WebTranslateIt
71
91
 
72
92
  def init
73
93
  api_key = Util.ask("Project API Key:")
74
- path = Util.ask("Configuration file path:", 'config/translation.yml')
75
- FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/'))
76
94
  project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
77
95
  project_info = project['project']
78
- if File.exists?(path) && !File.writable?(path)
79
- puts "Error: #{path} is not writable.".failure
96
+ if File.exists?('.wti') && !File.writable?('.wti')
97
+ puts "Error: `.wti` file is not writable.".failure
80
98
  exit
81
99
  end
82
- File.open(path, 'w'){ |file| file << generate_configuration(api_key, project_info) }
100
+ File.open('.wti', 'w'){ |file| file << generate_configuration(api_key, project_info) }
83
101
  puts ""
84
102
  puts "Done! You can now use `wti` to push and pull your language files."
85
103
  puts "Check `wti --help` for help."
@@ -87,7 +105,6 @@ module WebTranslateIt
87
105
 
88
106
  def match
89
107
  puts "Matching local files with File Manager".titleize
90
- puts ""
91
108
  configuration.files.find_all{ |mf| mf.locale == configuration.source_locale }.each do |master_file|
92
109
  if !File.exists?(master_file.file_path)
93
110
  puts master_file.file_path.failure + " (#{master_file.locale})"
@@ -149,6 +166,25 @@ module WebTranslateIt
149
166
  return locales.uniq
150
167
  end
151
168
 
169
+ def configuration_file_path
170
+ if File.exists?('config/translation.yml')
171
+ puts "Warning: `config/translation.yml` is deprecated in favour of a `.wti` file."
172
+ if Util.ask_yes_no("Would you like to migrate your configuration now?", true)
173
+ require 'fileutils'
174
+ if FileUtils.mv('config/translation.yml', '.wti')
175
+ return '.wti'
176
+ else
177
+ puts "Couldn’t move `config/translation.yml`."
178
+ return false
179
+ end
180
+ else
181
+ return 'config/translation.yml'
182
+ end
183
+ else
184
+ return '.wti'
185
+ end
186
+ end
187
+
152
188
  def generate_configuration(api_key, project_info)
153
189
  file = <<-FILE
154
190
  api_key: #{api_key}
@@ -3,7 +3,7 @@ module WebTranslateIt
3
3
 
4
4
  # Handles the configuration of your project, both via the the configuration file
5
5
  # and via the API.
6
- # Implementation example, assuming you have a valid config/translation.yml file:
6
+ # Implementation example, assuming you have a valid .wti file:
7
7
  #
8
8
  # configuration = WebTranslateIt::Configuration.new
9
9
  #
@@ -13,7 +13,7 @@ module WebTranslateIt
13
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
- def initialize(root_path = Rails.root, path_to_config_file = "config/translation.yml")
16
+ def initialize(root_path = Rails.root, path_to_config_file = ".wti")
17
17
  self.path = root_path
18
18
  self.logger = logger
19
19
  configuration = YAML.load_file(File.join(self.path, path_to_config_file))
@@ -137,6 +137,21 @@ class Array
137
137
  def to_columns
138
138
  " #{self[0].backward_truncate} | #{self[1]} #{self[2]}"
139
139
  end
140
+
141
+ def chunk(pieces=2)
142
+ len = self.length;
143
+ mid = (len/pieces)
144
+ chunks = []
145
+ start = 0
146
+ 1.upto(pieces) do |i|
147
+ last = start+mid
148
+ last = last-1 unless len%pieces >= i
149
+ chunks << self[start..last] || []
150
+ start = last+1
151
+ end
152
+ chunks
153
+ end
154
+
140
155
  end
141
156
 
142
157
  class String
data/readme.md CHANGED
@@ -9,7 +9,7 @@ Web Translate It
9
9
 
10
10
  `web_translate_it` is a rubygem providing tools to sync your language files with [Web Translate It](https://webtranslateit.com), a web-based translation software.
11
11
 
12
- ![Web Translate It](http://s3.amazonaws.com:80/edouard.baconfile.com/web_translate_it%2Fwti3.png)
12
+ ![Web Translate It](http://f.cl.ly/items/2X3m0h0g0I1O1U07163o/wti_example.jpg)
13
13
 
14
14
  This gem provides:
15
15
 
@@ -59,8 +59,6 @@ Execute `wti --help` to see the usage:
59
59
  See `wti <command> --help` for more information on a specific command.
60
60
 
61
61
  [options] are:
62
- --config, -c <s>: Path to a translation.yml file (default:
63
- config/translation.yml)
64
62
  --version, -v: Print version and exit
65
63
  --help, -h: Show this message
66
64
 
@@ -141,12 +139,16 @@ Sample Commands
141
139
  <td>wti status</td>
142
140
  <td>View project statistics</td>
143
141
  </tr>
142
+ <tr>
143
+ <td>wti match</td>
144
+ <td>Show matching between files on local computer and the ones in Web Translate It’s File Manager</td>
145
+ </tr>
144
146
  </table>
145
147
 
146
148
  Hooks
147
149
  -----
148
150
 
149
- It is sometimes useful to hook a command or a script before or after a push or a pull. One use-case would be to launch a build after pulling language files. You can do that by implementing hooks in your `translation.yml` file.
151
+ It is sometimes useful to hook a command or a script before or after a push or a pull. One use-case would be to launch a build after pulling language files. You can do that by implementing hooks in your `.wti` file.
150
152
 
151
153
  There are 4 hooks:
152
154
 
@@ -155,12 +157,12 @@ There are 4 hooks:
155
157
  * `before_push`
156
158
  * `after_push`
157
159
 
158
- Check the [sample `translation.yml`](https://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/translation.yml#L9..L13) file for implementation.
160
+ Check the [sample `.wti`](https://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/.wti#L9..L13) file for implementation.
159
161
 
160
162
  Web Translate It Synchronisation Console
161
163
  ----------------------------------------
162
164
 
163
- ![Web Translate It](http://s3.amazonaws.com:80/edouard.baconfile.com/web_translate_it%2Fadmin_console2.png)
165
+ ![Web Translate It](http://f.cl.ly/items/2Z413Q3A2b331c0O2m04/wti_server.png)
164
166
 
165
167
  `wti` contains a server you can use to run a friendly web interface to sync your translations. It allows a translation team to refresh the language files on a staging server without asking the developers to manually `wti pull`.
166
168
 
@@ -172,7 +174,7 @@ By default, it starts an application on localhost on the port 4000. You will fin
172
174
 
173
175
  Should you need to use another host or port, you can use the `-h` and `-p` options. For example: `wti server -p 1234`.
174
176
 
175
- You may want to run some commands before or after syncing translations. You can use the hooks to do so. For instance, you could add the following in your `translation.yml` file:
177
+ You may want to run some commands before or after syncing translations. You can use the hooks to do so. For instance, you could add the following in your `.wti` file:
176
178
 
177
179
  before_pull: "echo 'some unix command'"
178
180
  after_pull: "touch tmp/restart.txt"
@@ -14,7 +14,7 @@ describe WebTranslateIt::Configuration do
14
14
  "ignore_locales" => "en_GB"
15
15
  }
16
16
  YAML.should_receive(:load_file).and_return(config_hash)
17
- WebTranslateIt::Configuration.new(File.dirname(__FILE__) + '/../..', 'examples/translation.yml')
17
+ WebTranslateIt::Configuration.new(File.dirname(__FILE__) + '/../..', '.wti')
18
18
  end
19
19
 
20
20
  it "should assign the API key, files" do
data/version.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 8
4
- :tiny: 1
5
- :patch: 9
4
+ :tiny: 2
5
+ :patch: 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1.9
4
+ version: 1.8.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-07 00:00:00.000000000 Z
12
+ date: 2011-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
16
- requirement: &70281540470320 !ruby/object:Gem::Requirement
16
+ requirement: &70229730325800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70281540470320
24
+ version_requirements: *70229730325800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop
27
- requirement: &70281540468760 !ruby/object:Gem::Requirement
27
+ requirement: &70229730325300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.16.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70281540468760
35
+ version_requirements: *70229730325300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &70281540467180 !ruby/object:Gem::Requirement
38
+ requirement: &70229730324840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70281540467180
46
+ version_requirements: *70229730324840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70281540459200 !ruby/object:Gem::Requirement
49
+ requirement: &70229730324380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70281540459200
57
+ version_requirements: *70229730324380
58
58
  description:
59
59
  email: edouard@atelierconvivialite.com
60
60
  executables:
@@ -69,7 +69,6 @@ files:
69
69
  - readme.md
70
70
  - version.yml
71
71
  - examples/locale.rb
72
- - examples/translation.yml
73
72
  - lib/web_translate_it/auto_fetch.rb
74
73
  - lib/web_translate_it/cacert.pem
75
74
  - lib/web_translate_it/command_line.rb
@@ -82,7 +81,6 @@ files:
82
81
  - lib/web_translate_it/views/index.erb
83
82
  - lib/web_translate_it.rb
84
83
  - generators/webtranslateit/lib/insert_commands.rb
85
- - generators/webtranslateit/templates/translation.yml
86
84
  - generators/webtranslateit/webtranslateit_generator.rb
87
85
  - bin/wti
88
86
  - man/wti.1
@@ -1,13 +0,0 @@
1
- # The Project API Token from Web Translate It
2
- api_key: SECRET
3
-
4
- # Optional: locales not to sync with Web Translate It.
5
- # eg. [:en, :fr] or just 'en'
6
- # ignore_locales: :en
7
-
8
- # Optional
9
- # before_pull: "echo 'some unix command'" # Command executed before pulling files
10
- # after_pull: "touch tmp/restart.txt" # Command executed after pulling files
11
- #
12
- # before_push: "echo 'some unix command'" # Command executed before pushing files
13
- # after_push: "touch tmp/restart.txt" # Command executed after pushing files
@@ -1,6 +0,0 @@
1
- # The Project API Token from Web Translate It
2
- api_key: '<%= api_key %>'
3
-
4
- # Optional: locales not to sync with Web Translate It.
5
- # eg. [:en, :fr] or just 'en'
6
- # ignore_locales: '<%= project["source_locale"]["code"] %>'