web_translate_it 1.4.7 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -5
- data/history.md +11 -0
- data/lib/web_translate_it/command_line.rb +29 -53
- data/lib/web_translate_it/configuration.rb +9 -17
- data/lib/web_translate_it/tasks.rb +1 -1
- data/lib/web_translate_it/util.rb +1 -1
- data/version.yml +2 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
This is a gem providing tools to integrate your software to translate with [Web Translate It](https://webtranslateit.com), a web-based translation hub.
|
10
10
|
|
11
|
+
![Web Translate It](http://s3.amazonaws.com:80/edouard.baconfile.com/web_translate_it%2Fwti.png)
|
12
|
+
|
11
13
|
This gem provides your app with:
|
12
14
|
|
13
15
|
* an executable, `wti`, to upload and download language files from the command line (or in whatever else you want to execute it)
|
@@ -23,10 +25,8 @@ If your project if already set up on Web Translate It, run `wti autoconf` to gen
|
|
23
25
|
|
24
26
|
Run `wti --help` to see the usage:
|
25
27
|
|
26
|
-
Web Translate It
|
27
|
-
|
28
|
-
pull Pull language file(s) from Web Translate It.
|
29
|
-
push Push language file(s) to Web Translate It.
|
28
|
+
pull Pull target language file(s) from Web Translate It.
|
29
|
+
push Push master language file(s) to Web Translate It.
|
30
30
|
autoconf Configure your project to sync with Web Translate It.
|
31
31
|
|
32
32
|
OPTIONAL PARAMETERS:
|
@@ -34,7 +34,8 @@ Run `wti --help` to see the usage:
|
|
34
34
|
-l --locale The ISO code of a specific locale to pull or push.
|
35
35
|
-c --config Path to a translation.yml file. If this option
|
36
36
|
is absent, looks for config/translation.yml.
|
37
|
-
--
|
37
|
+
--all Respectively download or upload all files.
|
38
|
+
--force Force wti pull to re-download the language file,
|
38
39
|
regardless if local version is current.
|
39
40
|
OTHER:
|
40
41
|
------
|
data/history.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## Version 1.5.0 /2010-02-19
|
2
|
+
|
3
|
+
Warning, some deprecations in this version.
|
4
|
+
|
5
|
+
* Remove `wti fetch` and `wti upload`. It was deprecated in 1.4.7 in favour of `wti pull` and `wti push` respectively.
|
6
|
+
* `wti push` now only pushes the master language file. Use `wti push --all` to push all or `wti push -l [locale]` to push a specific locale.
|
7
|
+
* `wti pull` now only pulls the target language files. Use `wti pull --all` to pull all or `wti pull -l [locale]` to pull a specific locale.
|
8
|
+
* Increase read timeout to 40s — Required for very large projects.
|
9
|
+
* Bug fix: `wti autoconf` now create directory if it doesn't exist.
|
10
|
+
* Bug fix: `wti autoconf` now ask the user where are the locale files.
|
11
|
+
|
1
12
|
## Version 1.4.7 /2010-02-05
|
2
13
|
|
3
14
|
* Add deprecation warning for `wti --fetch`, `wti -f`. These commands will be deprecated in favour of `wti pull`.
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module WebTranslateIt
|
2
2
|
class CommandLine
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
OPTIONS = <<-OPTION
|
5
|
-
pull Pull language file(s) from Web Translate It.
|
6
|
-
push Push language file(s) to Web Translate It.
|
6
|
+
pull Pull target language file(s) from Web Translate It.
|
7
|
+
push Push master language file(s) to Web Translate It.
|
7
8
|
autoconf Configure your project to sync with Web Translate It.
|
8
9
|
|
9
10
|
OPTIONAL PARAMETERS:
|
@@ -11,6 +12,7 @@ OPTIONAL PARAMETERS:
|
|
11
12
|
-l --locale The ISO code of a specific locale to pull or push.
|
12
13
|
-c --config Path to a translation.yml file. If this option
|
13
14
|
is absent, looks for config/translation.yml.
|
15
|
+
--all Respectively download or upload all files.
|
14
16
|
--force Force wti pull to re-download the language file,
|
15
17
|
regardless if local version is current.
|
16
18
|
OTHER:
|
@@ -31,11 +33,6 @@ OPTION
|
|
31
33
|
show_version
|
32
34
|
when '-h', '--help'
|
33
35
|
show_options
|
34
|
-
# deprecated in 1.5.0
|
35
|
-
when '-f', '--fetch'
|
36
|
-
fetch
|
37
|
-
when '-u', '--upload'
|
38
|
-
upload
|
39
36
|
else
|
40
37
|
puts "Command not found"
|
41
38
|
show_options
|
@@ -44,7 +41,7 @@ OPTION
|
|
44
41
|
|
45
42
|
def self.pull
|
46
43
|
configuration = fetch_configuration
|
47
|
-
locales =
|
44
|
+
locales = fetch_locales_to_pull(configuration)
|
48
45
|
configuration.files.each do |file|
|
49
46
|
locales.each do |locale|
|
50
47
|
puts "Pulling #{file.file_path_for_locale(locale)}…"
|
@@ -55,7 +52,7 @@ OPTION
|
|
55
52
|
|
56
53
|
def self.push
|
57
54
|
configuration = fetch_configuration
|
58
|
-
locales =
|
55
|
+
locales = fetch_locales_to_push(configuration)
|
59
56
|
configuration.files.each do |file|
|
60
57
|
locales.each do |locale|
|
61
58
|
puts "Pushing #{file.file_path_for_locale(locale)}…"
|
@@ -72,11 +69,15 @@ OPTION
|
|
72
69
|
puts "You must enter your project API key provided by Web Translate It"
|
73
70
|
exit
|
74
71
|
end
|
75
|
-
puts "
|
76
|
-
puts "Enter below another path if you want to change, or leave it blank if the defaut path is okay."
|
72
|
+
puts "Where should we create the configuration file? (Default: `config/translation.yml`)"
|
77
73
|
path = STDIN.gets.strip
|
78
74
|
path = "config/translation.yml" if path == ""
|
79
|
-
|
75
|
+
FileUtils.mkpath(path.split('/')[0..path.split('/').size-1])
|
76
|
+
puts "Where are you language files located? (Default: `config/locales/`)"
|
77
|
+
path_to_locale_files = STDIN.gets.strip
|
78
|
+
path_to_locale_files = "config/locales/" if path_to_locale_files == ""
|
79
|
+
FileUtils.mkpath(path.split('/')[0..path.split('/').size-1])
|
80
|
+
File.open(path, 'w'){ |file| file << generate_configuration(api_key, path_to_locale_files) }
|
80
81
|
puts "Done! You can now use `wti` to push and pull your language files."
|
81
82
|
puts "Check `wti --help` for more information."
|
82
83
|
end
|
@@ -93,42 +94,6 @@ OPTION
|
|
93
94
|
puts "Web Translate It #{WebTranslateIt::Util.version}"
|
94
95
|
end
|
95
96
|
|
96
|
-
# deprecated in 1.5.0
|
97
|
-
def self.fetch
|
98
|
-
puts "Warning: this command is deprecated and will stop working in 1.5.0."
|
99
|
-
puts "Use `wti pull` instead. See help: `wti --help`"
|
100
|
-
configuration = WebTranslateIt::Configuration.new('.')
|
101
|
-
if ARGV.size == 2
|
102
|
-
locales = [ARGV[1]]
|
103
|
-
elsif ARGV.size == 1
|
104
|
-
locales = configuration.locales
|
105
|
-
end
|
106
|
-
configuration.files.each do |file|
|
107
|
-
locales.each do |locale|
|
108
|
-
puts "Fetching #{file.file_path_for_locale(locale)}…"
|
109
|
-
file.fetch(locale)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# deprecated in 1.5.0
|
115
|
-
def self.upload
|
116
|
-
puts "Warning: this command is deprecated and will stop working in 1.5.0."
|
117
|
-
puts "Use `wti push` instead. See help: `wti --help`"
|
118
|
-
configuration = WebTranslateIt::Configuration.new('.')
|
119
|
-
if ARGV.size == 2
|
120
|
-
locales = [ARGV[1]]
|
121
|
-
elsif ARGV.size == 1
|
122
|
-
locales = configuration.locales
|
123
|
-
end
|
124
|
-
configuration.files.each do |file|
|
125
|
-
locales.each do |locale|
|
126
|
-
puts "Uploading #{file.file_path} in #{locale}…"
|
127
|
-
file.upload(locale)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
97
|
def self.fetch_configuration
|
133
98
|
if (index = ARGV.index('-c') || ARGV.index('--config')).nil?
|
134
99
|
configuration = WebTranslateIt::Configuration.new('.')
|
@@ -138,16 +103,27 @@ OPTION
|
|
138
103
|
return configuration
|
139
104
|
end
|
140
105
|
|
141
|
-
def self.
|
106
|
+
def self.fetch_locales_to_pull(configuration)
|
107
|
+
if (index = ARGV.index('-l') || ARGV.index('--locale')).nil?
|
108
|
+
locales = configuration.target_locales
|
109
|
+
else
|
110
|
+
locales = [ARGV[index+1]]
|
111
|
+
end
|
112
|
+
locales.push(configuration.source_locale) if ARGV.index('--all')
|
113
|
+
return locales.uniq
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.fetch_locales_to_push(configuration)
|
142
117
|
if (index = ARGV.index('-l') || ARGV.index('--locale')).nil?
|
143
|
-
locales = configuration.
|
118
|
+
locales = [configuration.source_locale]
|
144
119
|
else
|
145
120
|
locales = [ARGV[index+1]]
|
146
121
|
end
|
147
|
-
|
122
|
+
locales.push(configuration.target_locales) if ARGV.index('--all')
|
123
|
+
return locales.uniq
|
148
124
|
end
|
149
125
|
|
150
|
-
def self.generate_configuration(api_key)
|
126
|
+
def self.generate_configuration(api_key, path_to_locale_files)
|
151
127
|
project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
152
128
|
project = project_info['project']
|
153
129
|
file = <<-FILE
|
@@ -168,7 +144,7 @@ files:
|
|
168
144
|
FILE
|
169
145
|
project["project_files"].each do |project_file|
|
170
146
|
if project_file["master"]
|
171
|
-
file << " #{project_file["id"]}:
|
147
|
+
file << " #{project_file["id"]}: #{path_to_locale_files}" + project_file["name"].gsub(project["source_locale"]["code"], "[locale]") + "\n"
|
172
148
|
end
|
173
149
|
end
|
174
150
|
return file
|
@@ -9,9 +9,9 @@ module WebTranslateIt
|
|
9
9
|
class Configuration
|
10
10
|
require 'yaml'
|
11
11
|
require 'fileutils'
|
12
|
-
attr_accessor :path, :api_key, :files, :ignore_locales, :logger
|
12
|
+
attr_accessor :path, :api_key, :source_locale, :target_locales, :files, :ignore_locales, :logger
|
13
13
|
|
14
|
-
# Load
|
14
|
+
# Load configuration file from the path.
|
15
15
|
def initialize(root_path=RAILS_ROOT, path_to_config="config/translation.yml")
|
16
16
|
self.path = root_path
|
17
17
|
configuration = YAML.load_file(File.join(root_path, path_to_config))
|
@@ -22,6 +22,7 @@ module WebTranslateIt
|
|
22
22
|
configuration['files'].each do |file_id, file_path|
|
23
23
|
self.files.push(TranslationFile.new(file_id, root_path + '/' + file_path, api_key))
|
24
24
|
end
|
25
|
+
set_locales
|
25
26
|
end
|
26
27
|
|
27
28
|
# Makes an API request to fetch the list of the different locales for a project.
|
@@ -29,25 +30,16 @@ module WebTranslateIt
|
|
29
30
|
#
|
30
31
|
# configuration = WebTranslateIt::Configuration.new
|
31
32
|
# locales = configuration.locales # returns an array of locales: ['en', 'fr', 'es', ...]
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
response = http.request(request)
|
38
|
-
if response.code.to_i >= 400 and response.code.to_i < 500
|
39
|
-
puts "----------------------------------------------------------------------"
|
40
|
-
puts "You API key seems to be misconfigured. It is currently #{self.api_key}."
|
41
|
-
puts "Change it in RAILS_ROOT/configuration/translation.yml."
|
42
|
-
else
|
43
|
-
response.body.split
|
44
|
-
end
|
45
|
-
end
|
33
|
+
def set_locales
|
34
|
+
project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
|
35
|
+
project = project_info['project']
|
36
|
+
self.source_locale = project['source_locale']['code']
|
37
|
+
self.target_locales = project['target_locales'].map{|locale| locale['code']}
|
46
38
|
end
|
47
39
|
|
48
40
|
# Convenience method which returns the endpoint for fetching a list of locales for a project.
|
49
41
|
def api_url
|
50
|
-
"/api/projects/#{api_key}
|
42
|
+
"/api/projects/#{api_key}.yaml"
|
51
43
|
end
|
52
44
|
|
53
45
|
# Returns a logger. If RAILS_DEFAULT_LOGGER is defined, use it, else, define a new logger.
|
@@ -17,7 +17,7 @@ namespace :trans do
|
|
17
17
|
task :all do
|
18
18
|
welcome_message
|
19
19
|
configuration = WebTranslateIt::Configuration.new
|
20
|
-
locales = configuration.
|
20
|
+
locales = configuration.target_locales
|
21
21
|
configuration.ignore_locales.each do |ignore|
|
22
22
|
locales.delete(ignore)
|
23
23
|
end
|
data/version.yml
CHANGED
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "\xC3\x89douard Bri\xC3\xA8re"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-19 00:00:00 +01:00
|
13
13
|
default_executable: wti
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|