web_translate_it 1.4.6 → 1.4.7

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/README.md CHANGED
@@ -18,20 +18,28 @@ This gem provides your app with:
18
18
 
19
19
  gem install web_translate_it
20
20
 
21
- That’s it! At this point you have the Web Translate It executable. Run `wti --help` to see the usage:
21
+ That’s it! At this point you have the Web Translate It executable.
22
+ If your project if already set up on Web Translate It, run `wti autoconf` to generate the configuration file.
23
+
24
+ Run `wti --help` to see the usage:
22
25
 
23
26
  Web Translate It Help:
24
27
  **********************
25
- -f --fetch [locale] Download all the files for your project.
26
- If a locale is specified, only download
27
- the file for that locale.
28
- -u --upload [locale] Upload your files for a locale.
29
- -v --version Show version.
30
- -h --help This page.
31
-
32
- ### Assumptions
33
-
34
- We assume you have a `config/translation.yml` file in your project containing the configuration to sync with Web Translate It. [Read about the configuration file in the wiki](http://wiki.github.com/AtelierConvivialite/webtranslateit/).
28
+ pull Pull language file(s) from Web Translate It.
29
+ push Push language file(s) to Web Translate It.
30
+ autoconf Configure your project to sync with Web Translate It.
31
+
32
+ OPTIONAL PARAMETERS:
33
+ --------------------
34
+ -l --locale The ISO code of a specific locale to pull or push.
35
+ -c --config Path to a translation.yml file. If this option
36
+ is absent, looks for config/translation.yml.
37
+ --force Force `wti pull` to re-download the language file,
38
+ regardless if local version is current.
39
+ OTHER:
40
+ ------
41
+ -v --version Show version.
42
+ -h --help This page.
35
43
 
36
44
  ## Specific tools for Ruby on Rails
37
45
 
@@ -82,6 +90,11 @@ The gem currently has been tested against the following versions of Rails:
82
90
 
83
91
  Please open a discussion on [our support site](http://help.webtranslateit.com) if you're using a version of Rails that is not listed above and the gem is not working properly.
84
92
 
93
+ # Acknowledgement
94
+
95
+ * The executable is very much inspired from the awesome [Gemcutter](http://gemcutter.org/) commands,
96
+ * The Rails generator has been pinched from [Hoptoad Notifier](http://github.com/thoughtbot/hoptoad_notifier/).
97
+
85
98
  # What is Web Translate It anyway?
86
99
 
87
100
  Web Translate It is a web-based translation hub to collaboratively translate software.
@@ -12,7 +12,7 @@ class WebtranslateitGenerator < Rails::Generator::Base
12
12
  end
13
13
  record do |m|
14
14
  if options[:api_key]
15
- project_details = YAML.load fetch_project_information(options[:api_key])
15
+ project_details = YAML.load WebTranslateIt::Project.fetch_info(options[:api_key])
16
16
  m.template 'translation.yml', 'config/translation.yml',
17
17
  :assigns => { :api_key => options[:api_key], :project => project_details["project"] }
18
18
  m.append_to 'Rakefile', "require 'web_translate_it/tasks' rescue LoadError"
@@ -23,22 +23,4 @@ class WebtranslateitGenerator < Rails::Generator::Base
23
23
  def api_key_configured?
24
24
  File.exists?('config/translations.yml')
25
25
  end
26
-
27
- def fetch_project_information(api_key)
28
- WebTranslateIt::Util.http_connection do |http|
29
- request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
30
- response = http.request(request)
31
- if response.code.to_i >= 400 and response.code.to_i < 500
32
- puts "We had a problem connecting to Web Translate It with this API key."
33
- puts "Make sure it is correct."
34
- exit
35
- elsif response.code.to_i >= 500
36
- puts "Web Translate It is temporarily unavailable. Please try again shortly."
37
- exit
38
- else
39
- return response.body
40
- end
41
- end
42
-
43
- end
44
26
  end
data/history.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## Version 1.4.7 /2010-02-05
2
+
3
+ * Add deprecation warning for `wti --fetch`, `wti -f`. These commands will be deprecated in favour of `wti pull`.
4
+ * Add deprecation warning for `wti --upload`, `wti -u`. These commands will be deprecated in favour of `wti push`.
5
+ * Add -c parameter to specify a configuration file at a custom location.
6
+ * Add -l parameter to specify a specific language file to pull or push (only works with `wti pull` and `wti push`).
7
+ * Add --force parameter to force Web Translate It to send the language files again, regardless if the current
8
+ language file version is current (this makes `wti pull` very much slower).
9
+ * Add `wti autoconf` command to automatically configure your project for Web Translate It.
10
+
1
11
  ## Version 1.4.6 /2010-02-04
2
12
 
3
13
  * Add feedback when using the `wti command`.
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), 'web_translate_it', 'configuration')
3
3
  require File.join(File.dirname(__FILE__), 'web_translate_it', 'translation_file')
4
4
  require File.join(File.dirname(__FILE__), 'web_translate_it', 'auto_fetch')
5
5
  require File.join(File.dirname(__FILE__), 'web_translate_it', 'command_line')
6
+ require File.join(File.dirname(__FILE__), 'web_translate_it', 'project')
6
7
 
7
8
  module WebTranslateIt
8
9
  def self.fetch_translations
@@ -2,32 +2,101 @@ module WebTranslateIt
2
2
  class CommandLine
3
3
 
4
4
  OPTIONS = <<-OPTION
5
- -f --fetch [locale] Download all the files for your project.
6
- If a locale is specified, only download
7
- the file for that locale.
8
- -u --upload [locale] Upload your files for a locale.
9
- -v --version Show version.
10
- -h --help This page.
5
+ pull Pull language file(s) from Web Translate It.
6
+ push Push language file(s) to Web Translate It.
7
+ autoconf Configure your project to sync with Web Translate It.
8
+
9
+ OPTIONAL PARAMETERS:
10
+ --------------------
11
+ -l --locale The ISO code of a specific locale to pull or push.
12
+ -c --config Path to a translation.yml file. If this option
13
+ is absent, looks for config/translation.yml.
14
+ --force Force wti pull to re-download the language file,
15
+ regardless if local version is current.
16
+ OTHER:
17
+ ------
18
+ -v --version Show version.
19
+ -h --help This page.
11
20
  OPTION
12
21
 
13
22
  def self.run
14
23
  case ARGV[0]
15
- when '-f', '--fetch'
16
- fetch
17
- when '-u', '--upload'
18
- upload
24
+ when 'pull'
25
+ pull
26
+ when 'push'
27
+ push
28
+ when 'autoconf'
29
+ autoconf
19
30
  when '-v', '--version'
20
31
  show_version
21
32
  when '-h', '--help'
22
33
  show_options
34
+ # deprecated in 1.5.0
35
+ when '-f', '--fetch'
36
+ fetch
37
+ when '-u', '--upload'
38
+ upload
23
39
  else
24
40
  puts "Command not found"
25
41
  show_options
26
42
  end
27
43
  end
44
+
45
+ def self.pull
46
+ configuration = fetch_configuration
47
+ locales = fetch_locales(configuration)
48
+ configuration.files.each do |file|
49
+ locales.each do |locale|
50
+ puts "Pulling #{file.file_path_for_locale(locale)}…"
51
+ file.fetch(locale, ARGV.index('--force'))
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.push
57
+ configuration = fetch_configuration
58
+ locales = fetch_locales(configuration)
59
+ configuration.files.each do |file|
60
+ locales.each do |locale|
61
+ puts "Pushing #{file.file_path_for_locale(locale)}…"
62
+ file.upload(locale)
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.autoconf
68
+ puts "We will attempt to configure your project automagically"
69
+ puts "Please enter your project API Key:"
70
+ api_key = STDIN.gets.strip
71
+ if api_key == ""
72
+ puts "You must enter your project API key provided by Web Translate It"
73
+ exit
74
+ end
75
+ puts "We will now create a `config/translation.yml` file in the current directory."
76
+ puts "Enter below another path if you want to change, or leave it blank if the defaut path is okay."
77
+ path = STDIN.gets.strip
78
+ path = "config/translation.yml" if path == ""
79
+ File.open(path, 'w'){ |file| file << generate_configuration(api_key) }
80
+ puts "Done! You can now use `wti` to push and pull your language files."
81
+ puts "Check `wti --help` for more information."
82
+ end
83
+
84
+ def self.show_options
85
+ puts ""
86
+ puts "Web Translate It Help:"
87
+ puts "**********************"
88
+ $stdout.puts OPTIONS
89
+ end
28
90
 
91
+ def self.show_version
92
+ puts ""
93
+ puts "Web Translate It #{WebTranslateIt::Util.version}"
94
+ end
95
+
96
+ # deprecated in 1.5.0
29
97
  def self.fetch
30
- #TODO: Ability to pass a path as an argument
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`"
31
100
  configuration = WebTranslateIt::Configuration.new('.')
32
101
  if ARGV.size == 2
33
102
  locales = [ARGV[1]]
@@ -42,8 +111,10 @@ OPTION
42
111
  end
43
112
  end
44
113
 
114
+ # deprecated in 1.5.0
45
115
  def self.upload
46
- #TODO: Ability to pass a path as an argument
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`"
47
118
  configuration = WebTranslateIt::Configuration.new('.')
48
119
  if ARGV.size == 2
49
120
  locales = [ARGV[1]]
@@ -58,16 +129,49 @@ OPTION
58
129
  end
59
130
  end
60
131
 
61
- def self.show_options
62
- puts ""
63
- puts "Web Translate It Help:"
64
- puts "**********************"
65
- $stdout.puts OPTIONS
132
+ def self.fetch_configuration
133
+ if (index = ARGV.index('-c') || ARGV.index('--config')).nil?
134
+ configuration = WebTranslateIt::Configuration.new('.')
135
+ else
136
+ configuration = WebTranslateIt::Configuration.new('.', ARGV[index+1])
137
+ end
138
+ return configuration
66
139
  end
67
140
 
68
- def self.show_version
69
- puts ""
70
- puts "Web Translate It #{WebTranslateIt::Util.version}"
141
+ def self.fetch_locales(configuration)
142
+ if (index = ARGV.index('-l') || ARGV.index('--locale')).nil?
143
+ locales = configuration.locales
144
+ else
145
+ locales = [ARGV[index+1]]
146
+ end
147
+ return locales
148
+ end
149
+
150
+ def self.generate_configuration(api_key)
151
+ project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
152
+ project = project_info['project']
153
+ file = <<-FILE
154
+ api_key: #{api_key}
155
+
156
+ # The locales not to sync with Web Translate It.
157
+ # Pass an array of string, or an array of symbols, a string or a symbol.
158
+ # eg. [:en, :fr] or just 'en'
159
+ ignore_locales: '#{project["source_locale"]["code"]}'
160
+
161
+ # A list of files to translate
162
+ # You can name your language files as you want, as long as the locale name match the
163
+ # locale name you set in Web Translate It, and that the different language files names are
164
+ # differenciated by their locale name.
165
+ # For example, if you set to translate a project in en_US in WTI, you should use the locale en_US in your app
166
+ #
167
+ files:
168
+ FILE
169
+ project["project_files"].each do |project_file|
170
+ if project_file["master"]
171
+ file << " #{project_file["id"]}: config/locales/" + project_file["name"].gsub(project["source_locale"]["code"], "[locale]") + "\n"
172
+ end
173
+ end
174
+ return file
71
175
  end
72
176
  end
73
177
  end
@@ -0,0 +1,21 @@
1
+ module WebTranslateIt
2
+ class Project
3
+
4
+ def self.fetch_info(api_key)
5
+ WebTranslateIt::Util.http_connection do |http|
6
+ request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
7
+ response = http.request(request)
8
+ if response.code.to_i >= 400 and response.code.to_i < 500
9
+ puts "We had a problem connecting to Web Translate It with this API key."
10
+ puts "Make sure it is correct."
11
+ exit
12
+ elsif response.code.to_i >= 500
13
+ puts "Web Translate It is temporarily unavailable. Please try again shortly."
14
+ exit
15
+ else
16
+ return response.body
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
data/version.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 4
4
- :patch: 6
4
+ :patch: 7
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.6
4
+ version: 1.4.7
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-04 00:00:00 +01:00
12
+ date: 2010-02-05 00:00:00 +01:00
13
13
  default_executable: wti
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ files:
61
61
  - lib/web_translate_it/auto_fetch.rb
62
62
  - lib/web_translate_it/command_line.rb
63
63
  - lib/web_translate_it/configuration.rb
64
+ - lib/web_translate_it/project.rb
64
65
  - lib/web_translate_it/tasks.rb
65
66
  - lib/web_translate_it/translation_file.rb
66
67
  - lib/web_translate_it/util.rb