web_translate_it 1.7.0.7 → 1.7.1.pre1

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
@@ -4,12 +4,12 @@
4
4
  [RDocs](http://yardoc.org/docs/AtelierConvivialite-webtranslateit) |
5
5
  [Example app](http://github.com/AtelierConvivialite/rails_example_app) |
6
6
  [Report a bug](http://github.com/AtelierConvivialite/webtranslateit/issues) |
7
- [Support](http://help.webtranslateit.com)
7
+ [Support](http://help.webtranslateit.com) |
8
8
  [Documentation](http://docs.webtranslateit.com/web_translate_it_client/)
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 computer-aided translation tool.
11
11
 
12
- ![Web Translate It](http://s3.amazonaws.com:80/edouard.baconfile.com/web_translate_it%2Fwti.png)
12
+ ![Web Translate It](http://s3.amazonaws.com:80/edouard.baconfile.com/web_translate_it%2Fwti2.png)
13
13
 
14
14
  This gem provides 4 tools:
15
15
 
@@ -178,6 +178,7 @@ The gem currently has been tested against the following versions of Rails:
178
178
 
179
179
  * 2.3.4
180
180
  * 2.3.5
181
+ * 2.3.10
181
182
 
182
183
  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.
183
184
 
data/examples/en.yml ADDED
@@ -0,0 +1,6 @@
1
+ fr:
2
+ another_one: dskjdks
3
+ another_string: "this is another string"
4
+ hello: "Hello world!!"
5
+ new_string: hehe
6
+ test: " & & "
data/history.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## Edge
2
+
3
+ * New: TranslationFile#fetch now use file timestamps served by the Project API.
4
+ This makes `wti pull` much faster, especially for projects having a lot of files
5
+ * Fix: `wti server` now notice new languages.
6
+ Each page request to `wti server` now reloads the project information from Web Translate It.
7
+
8
+
1
9
  ## Version 1.7.0.7 / 2010-11-15
2
10
 
3
11
  * Fix connection problems through a proxy (1.7.0.7.pre)
@@ -101,7 +101,7 @@ module WebTranslateIt
101
101
 
102
102
  def fetch_locales_to_pull
103
103
  if options.locale
104
- locales = [options.locale]
104
+ locales = [Util.sanitize_locale(options.locale)]
105
105
  else
106
106
  locales = configuration.target_locales
107
107
  configuration.ignore_locales.each{ |locale_to_delete| locales.delete(locale_to_delete) }
@@ -112,7 +112,7 @@ module WebTranslateIt
112
112
 
113
113
  def fetch_locales_to_push(configuration)
114
114
  if options.locale
115
- locales = [options.locale]
115
+ locales = [Util.sanitize_locale(options.locale)]
116
116
  else
117
117
  locales = [configuration.source_locale]
118
118
  end
@@ -47,7 +47,7 @@ module WebTranslateIt
47
47
  if project_file['name'].nil? or project_file['name'].strip == ''
48
48
  puts "File #{project_file['id']} not set up"
49
49
  else
50
- self.files.push TranslationFile.new(project_file['id'], project_file['name'], project_file['locale_code'], self.api_key)
50
+ self.files.push TranslationFile.new(project_file['id'], project_file['name'], project_file['locale_code'], self.api_key, project_file['updated_at'])
51
51
  end
52
52
  end
53
53
  end
@@ -26,14 +26,17 @@ module WebTranslateIt
26
26
  end
27
27
 
28
28
  get '/' do
29
+ @config = WebTranslateIt::Configuration.new('.')
29
30
  erb :index, :locals => { :config => config, :locale => "" }
30
31
  end
31
32
 
32
33
  get '/:locale' do
34
+ @config = WebTranslateIt::Configuration.new('.')
33
35
  erb :index, :locals => { :config => config, :locale => params[:locale] }
34
36
  end
35
37
 
36
38
  post '/pull/' do
39
+ @config = WebTranslateIt::Configuration.new('.')
37
40
  `#{config.before_pull}` if config.before_pull
38
41
  `wti pull`
39
42
  `#{config.after_pull}` if config.after_pull
@@ -41,17 +44,13 @@ module WebTranslateIt
41
44
  end
42
45
 
43
46
  post '/pull/:locale' do
47
+ @config = WebTranslateIt::Configuration.new('.')
44
48
  `#{config.before_pull}` if config.before_pull
45
49
  `wti pull -l #{params[:locale]}`
46
50
  `#{config.after_pull}` if config.after_pull
47
51
  redirect "/#{params[:locale]}"
48
52
  end
49
-
50
- def initialize(*args)
51
- super
52
- @config = WebTranslateIt::Configuration.new('.')
53
- end
54
-
53
+
55
54
  def self.start(host, port)
56
55
  WebTranslateIt::Server.run! :host => host, :port => port
57
56
  end
@@ -12,13 +12,14 @@ module WebTranslateIt
12
12
  require 'time'
13
13
  require 'fileutils'
14
14
 
15
- attr_accessor :id, :file_path, :locale, :api_key
15
+ attr_accessor :id, :file_path, :locale, :api_key, :updated_at
16
16
 
17
- def initialize(id, file_path, locale, api_key)
18
- self.id = id
19
- self.file_path = file_path
20
- self.locale = locale
21
- self.api_key = api_key
17
+ def initialize(id, file_path, locale, api_key, updated_at)
18
+ self.id = id
19
+ self.file_path = file_path
20
+ self.locale = locale
21
+ self.api_key = api_key
22
+ self.updated_at = updated_at
22
23
  end
23
24
 
24
25
  # Fetch a language file.
@@ -34,23 +35,25 @@ module WebTranslateIt
34
35
  # file.fetch(true) # force to re-download the file, will return the content of the file with a 200 OK
35
36
  #
36
37
  def fetch(force = false)
37
- begin
38
- WebTranslateIt::Util.http_connection do |http|
39
- request = Net::HTTP::Get.new(api_url)
40
- request.add_field('If-Modified-Since', last_modification) if File.exist?(self.file_path) and !force
41
- response = http.request(request)
42
- FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
43
- begin
44
- File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
45
- Util.handle_response(response)
46
- rescue
47
- "\n/!\\ An error occured: #{$!}"
38
+ if !File.exist?(self.file_path) or force or self.updated_at >= last_modification.utc
39
+ begin
40
+ WebTranslateIt::Util.http_connection do |http|
41
+ request = Net::HTTP::Get.new(api_url)
42
+ request.add_field('If-Modified-Since', last_modification.rfc2822) if File.exist?(self.file_path) and !force
43
+ response = http.request(request)
44
+ FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
45
+ begin
46
+ File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
47
+ Util.handle_response(response)
48
+ rescue
49
+ "\n/!\\ An error occured: #{$!}"
50
+ end
48
51
  end
52
+ rescue Timeout::Error
53
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
54
+ sleep(5)
55
+ fetch(force)
49
56
  end
50
- rescue Timeout::Error
51
- puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
52
- sleep(5)
53
- fetch(force)
54
57
  end
55
58
  end
56
59
 
@@ -126,7 +129,7 @@ module WebTranslateIt
126
129
 
127
130
  # Convenience method which returns the date of last modification of a language file.
128
131
  def last_modification
129
- File.mtime(File.new(self.file_path, 'r')).rfc2822
132
+ File.mtime(File.new(self.file_path, 'r'))
130
133
  end
131
134
 
132
135
  # Convenience method which returns the URL of the API endpoint for a locale.
@@ -128,5 +128,13 @@ module WebTranslateIt
128
128
  return list[result], result
129
129
  end
130
130
 
131
+ ##
132
+ # Cleans up a locale name
133
+ # For instance: passing `fr_FR` will return `fr-FR`
134
+
135
+ def self.sanitize_locale(locale)
136
+ locale.gsub('_', '-')
137
+ end
138
+
131
139
  end
132
140
  end
data/version.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 7
4
- :tiny: 0
5
- :patch: 7
4
+ :tiny: 1
5
+ :patch: pre1
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- hash: 105
5
- prerelease: false
4
+ prerelease: true
6
5
  segments:
7
6
  - 1
8
7
  - 7
9
- - 0
10
- - 7
11
- version: 1.7.0.7
8
+ - 1
9
+ - pre1
10
+ version: 1.7.1.pre1
12
11
  platform: ruby
13
12
  authors:
14
13
  - "\xC3\x89douard Bri\xC3\xA8re"
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-11-15 00:00:00 +01:00
18
+ date: 2010-12-23 00:00:00 +01:00
20
19
  default_executable: wti
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -27,7 +26,6 @@ dependencies:
27
26
  requirements:
28
27
  - - ~>
29
28
  - !ruby/object:Gem::Version
30
- hash: 15
31
29
  segments:
32
30
  - 1
33
31
  - 0
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 19
46
43
  segments:
47
44
  - 0
48
45
  - 1
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ~>
60
57
  - !ruby/object:Gem::Version
61
- hash: 15
62
58
  segments:
63
59
  - 1
64
60
  - 0
@@ -73,7 +69,6 @@ dependencies:
73
69
  requirements:
74
70
  - - ">="
75
71
  - !ruby/object:Gem::Version
76
- hash: 13
77
72
  segments:
78
73
  - 1
79
74
  - 2
@@ -95,6 +90,7 @@ files:
95
90
  - MIT-LICENSE
96
91
  - README.md
97
92
  - version.yml
93
+ - examples/en.yml
98
94
  - examples/locale.rb
99
95
  - examples/translation.yml
100
96
  - lib/web_translate_it/auto_fetch.rb
@@ -138,19 +134,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
134
  requirements:
139
135
  - - ">="
140
136
  - !ruby/object:Gem::Version
141
- hash: 3
142
137
  segments:
143
138
  - 0
144
139
  version: "0"
145
140
  required_rubygems_version: !ruby/object:Gem::Requirement
146
141
  none: false
147
142
  requirements:
148
- - - ">="
143
+ - - ">"
149
144
  - !ruby/object:Gem::Version
150
- hash: 3
151
145
  segments:
152
- - 0
153
- version: "0"
146
+ - 1
147
+ - 3
148
+ - 1
149
+ version: 1.3.1
154
150
  requirements: []
155
151
 
156
152
  rubyforge_project: