web_translate_it 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -59
- data/generators/webtranslateit/lib/insert_commands.rb +34 -0
- data/generators/webtranslateit/templates/translation.yml +17 -0
- data/generators/webtranslateit/webtranslateit_generator.rb +44 -0
- data/history.md +5 -0
- data/lib/web_translate_it/configuration.rb +0 -8
- data/lib/web_translate_it/tasks.rb +1 -7
- data/spec/web_translate_it/util_spec.rb +10 -0
- data/spec/web_translate_it_spec.rb +27 -0
- data/version.yml +1 -1
- metadata +32 -7
data/README.md
CHANGED
@@ -1,57 +1,37 @@
|
|
1
|
-
# Web Translate It
|
1
|
+
# Web Translate It
|
2
2
|
|
3
|
-
|
3
|
+
[RDocs](http://yardoc.org/docs/AtelierConvivialite-webtranslateit) | [Metrics](http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2FAtelierConvivialite%2Fwebtranslateit.git) | [Tests](http://runcoderun.com/AtelierConvivialite/webtranslateit/builds/74a78c2b382cb1856fa0964ed4ad372b50872844/1/ruby_186) |
|
4
|
+
[Example app](http://github.com/AtelierConvivialite/rails_example_app)
|
5
|
+
|
6
|
+
This is a gem providing tools to integrate your app with [Web Translate It](https://webtranslateit.com).
|
4
7
|
|
5
8
|
This gem provides your app with:
|
6
9
|
|
7
|
-
* a
|
10
|
+
* a handful of rake task to fetch your translations.
|
8
11
|
* a rack middleware to automatically fetch new translations from Web Translate It.
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
* See a [Rails 2.3 example app](http://github.com/AtelierConvivialite/rails_example_app) using it.
|
13
|
-
* All the necessary changes have been made in [this commit](http://github.com/AtelierConvivialite/rails_example_app/commit/d88e4aa62b061f215d1784d76c94cd8613efc9bb)
|
13
|
+
## Installation
|
14
14
|
|
15
|
-
|
15
|
+
* Add to your config/environments.rb:
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
`config.gem 'web_translate_it', :version => '~> 1.4.2', :source => 'http://gemcutter.org'`
|
17
|
+
`config.gem 'web_translate_it'`
|
20
18
|
|
21
19
|
* Then, run:
|
22
20
|
|
23
21
|
`rake gems:install`
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
* Add in your `Rakefile` to add Web Translate It’s rake tasks:
|
23
|
+
* Copy/paste your api key from Web Translate It and run:
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
* Run:
|
32
|
-
|
33
|
-
`rake trans:config`
|
25
|
+
`script/generate webtranslateit --api-key your_key_here`
|
34
26
|
|
35
|
-
|
27
|
+
The generator does two things:
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
`api_key` is the API key (or token) provided per project by Web Translate It.
|
43
|
-
|
44
|
-
`ignore_locales` is an array of symbols, an array of strings, a symbol or a string of locales not to sync with Web Translate It. You usually don’t want to sync your master language files.
|
45
|
-
|
46
|
-
`wti_id1` is the id of your *master* language file on Web Translate It. If you only have one language file, then only put this one in the configuration file.
|
47
|
-
|
48
|
-
`config/locales/file1_[locale].yml` is the name of your language file on your project. To keep things simple, the gem makes the reasonable assumption that you differentiate your language files using the locale name. For example, you will have `file1_en.yml` for English, and `file1_fr.yml` for French. Replace `en` or `fr` by `[locale]` and the gem will update the files `file1_en.yml` and `file1_fr.yml`.
|
49
|
-
|
50
|
-
The gem also assume that you use the same locale name on your project and on Web Translate It. For example if you use the locale `fr_FR` on Web Translate It, then you should use `fr_FR` on your project.
|
51
|
-
|
52
|
-
### Rake tasks provided
|
29
|
+
* It adds a auto-configured `config/translation.yml` file using Web Translate It’s API.
|
30
|
+
* It adds `require 'web_translate_it/tasks' rescue LoadError` to your `Rakefile`
|
31
|
+
|
32
|
+
## Rake tasks provided
|
53
33
|
|
54
|
-
The gem provides
|
34
|
+
The gem provides 3 rake tasks.
|
55
35
|
|
56
36
|
rake trans:fetch:all
|
57
37
|
|
@@ -65,27 +45,19 @@ Fetch the latest translations for all the languages defined in Web Translate It
|
|
65
45
|
|
66
46
|
Upload to Web Translate It your files in a specific locale defined in Web Translate It’s interface.
|
67
47
|
|
68
|
-
|
69
|
-
|
70
|
-
Copy a `translation.yml` file to `config/translation.yml` if the file doesn’t exist.
|
71
|
-
|
72
|
-
### Automatically fetch new language files
|
48
|
+
## Optional: automatically fetch new language files for each page request
|
73
49
|
|
74
|
-
This
|
50
|
+
This should not be used on production. This allows to translate text on Web Translate It, reload a page on your site and see the translations appear.
|
75
51
|
|
76
|
-
|
52
|
+
### Rails 2.3 and newer
|
77
53
|
|
78
54
|
Use the rack middleware!
|
79
55
|
|
80
|
-
* Before starting up anything, you need to have a rack middleware setup to assign the value of the current locale to
|
81
|
-
|
82
|
-
|
83
|
-
Ryan Tomakyo’s [locale.rb](http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb).
|
84
|
-
You can also find an example of a very simple middleware using the `locale` parameter in
|
85
|
-
[examples/locale.rb](http://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/locale.rb).
|
56
|
+
* Before starting up anything, you need to have a rack middleware setup to assign the value of the current locale to `I18n.locale`.
|
57
|
+
This is very much specific to your app, this is left as an exercise to the reader. You can inspire yourself from Ryan Tomakyo’s [locale.rb](http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb).
|
58
|
+
You can also find an example of a very simple middleware using the `locale` parameter in [examples/locale.rb](http://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/locale.rb).
|
86
59
|
|
87
|
-
* The next step is to setup the `autofetch` middleware. Add in `config/environments/development.rb` and any other
|
88
|
-
environments you want to autofetch this line:
|
60
|
+
* The next step is to setup the `autofetch` middleware. Add in `config/environments/development.rb` and any other environments you want to autofetch this line:
|
89
61
|
|
90
62
|
config.middleware.use "WebTranslateIt::AutoFetch"
|
91
63
|
|
@@ -96,7 +68,7 @@ Use the rack middleware!
|
|
96
68
|
|
97
69
|
* That’s it!
|
98
70
|
|
99
|
-
|
71
|
+
### Rails older than 2.3 (works also for 2.3 and newer)
|
100
72
|
|
101
73
|
* Add the following lines in your `ApplicationController`:
|
102
74
|
|
@@ -119,17 +91,17 @@ end</pre>
|
|
119
91
|
|
120
92
|
## Supported Rails Versions
|
121
93
|
|
122
|
-
The gem currently has been tested against the following
|
94
|
+
The gem currently has been tested against the following versions of Rails:
|
123
95
|
|
124
96
|
* 2.3.4
|
125
97
|
* 2.3.5
|
126
98
|
|
127
|
-
Please open a discussion on [
|
99
|
+
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.
|
128
100
|
|
129
|
-
|
101
|
+
# What is Web Translate It anyway?
|
130
102
|
|
131
|
-
Web Translate It is
|
103
|
+
Web Translate It is an easy to use web-based translation hub to collaboratively translate software.
|
132
104
|
|
133
|
-
|
105
|
+
To learn more about it, please visit our [tour page](https://webtranslateit.com/tour).
|
134
106
|
|
135
|
-
|
107
|
+
This gem is released under the MIT License.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
2
|
+
|
3
|
+
Rails::Generator::Commands::Base.class_eval do
|
4
|
+
def file_contains?(relative_destination, line)
|
5
|
+
File.read(destination_path(relative_destination)).include?(line)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rails::Generator::Commands::Create.class_eval do
|
10
|
+
def append_to(file, line)
|
11
|
+
logger.insert "#{line} appended to #{file}"
|
12
|
+
unless options[:pretend] || file_contains?(file, line)
|
13
|
+
File.open(file, "a") do |file|
|
14
|
+
file.puts
|
15
|
+
file.puts line
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
22
|
+
def append_to(file, line)
|
23
|
+
logger.remove "#{line} removed from #{file}"
|
24
|
+
unless options[:pretend]
|
25
|
+
gsub_file file, "\n#{line}", ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails::Generator::Commands::List.class_eval do
|
31
|
+
def append_to(file, line)
|
32
|
+
logger.insert "#{line} appended to #{file}"
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# The Project API Token from Web Translate It
|
2
|
+
api_key: '<%= api_key %>'
|
3
|
+
|
4
|
+
# The locales not to sync with Web Translate It.
|
5
|
+
# Pass an array of string, or an array of symbols, a string or a symbol.
|
6
|
+
# eg. [:en, :fr] or just 'en'
|
7
|
+
ignore_locales: '<%= project["source_locale"]["code"] %>'
|
8
|
+
|
9
|
+
# A list of files to translate
|
10
|
+
# You can name your language files as you want, as long as the locale name match the
|
11
|
+
# locale name you set in Web Translate It, and that the different language files names are
|
12
|
+
# differenciated by their locale name.
|
13
|
+
# For example, if you set to translate a project in en_US in WTI, you should use the locale en_US in your app
|
14
|
+
#
|
15
|
+
# wti_id is the file id from Web Translate It.
|
16
|
+
files:
|
17
|
+
<% project["project_files"].each do |project_file| -%><% if project_file["master"] -%> <%= project_file["id"] %>: config/locales/<%= project_file["name"].gsub(project["source_locale"]["code"], "[locale]") %><% end %><% end -%>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
|
3
|
+
class WebtranslateitGenerator < Rails::Generator::Base
|
4
|
+
def add_options!(opt)
|
5
|
+
opt.on('-k', '--api-key=key', String, "Your Web Translate It API key") {|v| options[:api_key] = v}
|
6
|
+
end
|
7
|
+
|
8
|
+
def manifest
|
9
|
+
if !api_key_configured? && !options[:api_key]
|
10
|
+
puts "You must pass --api-key or create config/translations.yml"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
record do |m|
|
14
|
+
if options[:api_key]
|
15
|
+
project_details = YAML.load fetch_project_information(options[:api_key])
|
16
|
+
m.template 'translation.yml', 'config/translation.yml',
|
17
|
+
:assigns => { :api_key => options[:api_key], :project => project_details["project"] }
|
18
|
+
m.append_to 'Rakefile', "require 'web_translate_it/tasks' rescue LoadError"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def api_key_configured?
|
24
|
+
File.exists?('config/translations.yml')
|
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
|
+
end
|
data/history.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## Version 1.4.4 / 2010-02-02
|
2
|
+
|
3
|
+
* Add generator to automatically configure your project, given a Web Translate It API key.
|
4
|
+
* Remove rake trans:config, as configuration is now handled by the generator.
|
5
|
+
|
1
6
|
## Version 1.4.3 / 2010-01-09
|
2
7
|
|
3
8
|
* Remove colour outputs as it increases code complexity and doesn't add any value.
|
@@ -30,14 +30,6 @@ module WebTranslateIt
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.create_config_file
|
34
|
-
config_file = "config/translation.yml"
|
35
|
-
unless File.exists?(config_file)
|
36
|
-
puts "Created #{config_file}"
|
37
|
-
FileUtils.copy File.join(File.dirname(__FILE__), '..', '..', 'examples', 'translation.yml'), config_file
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
33
|
def api_url
|
42
34
|
"/api/projects/#{api_key}/locales"
|
43
35
|
end
|
@@ -41,13 +41,7 @@ namespace :trans do
|
|
41
41
|
handle_response(file.file_path_for_locale(args.locale), response_code)
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
|
-
desc "Install Web Translate It for your application"
|
46
|
-
task :config do
|
47
|
-
welcome_message
|
48
|
-
WebTranslateIt::Configuration.create_config_file
|
49
|
-
end
|
50
|
-
|
44
|
+
|
51
45
|
def handle_response(file_path, response_code)
|
52
46
|
if response_code < 400
|
53
47
|
puts "#{file_path}: #{response_code}, OK"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
module WebTranslateIt
|
4
|
+
class I18n
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe WebTranslateIt do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
WebTranslateIt::I18n.stub(:locale => 'en')
|
12
|
+
WebTranslateIt::Configuration.const_set("RAILS_ROOT", File.dirname(__FILE__) + '/examples')
|
13
|
+
@configuration = WebTranslateIt::Configuration.new
|
14
|
+
@file = mock(WebTranslateIt::TranslationFile)
|
15
|
+
@file.stub(:fetch => true)
|
16
|
+
@configuration.stub(:files => [@file])
|
17
|
+
WebTranslateIt::Configuration.stub(:new => @configuration)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "WebTranslateIt.fetch_translations" do
|
22
|
+
it "should fetch the configuration" do
|
23
|
+
WebTranslateIt::Configuration.should_receive(:new)
|
24
|
+
WebTranslateIt.fetch_translations
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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.
|
4
|
+
version: 1.4.4
|
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-
|
12
|
+
date: 2010-02-02 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,26 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "1.0"
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mg
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.0.7
|
44
|
+
version:
|
25
45
|
description: A rack middleware and a handful of rake tasks to sync your translations between webtranslateit.com and your rails applications.
|
26
46
|
email: edouard@atelierconvivialite.com
|
27
47
|
executables: []
|
@@ -37,13 +57,16 @@ files:
|
|
37
57
|
- version.yml
|
38
58
|
- examples/locale.rb
|
39
59
|
- examples/translation.yml
|
40
|
-
- lib/web_translate_it.rb
|
41
60
|
- lib/web_translate_it/auto_fetch.rb
|
42
61
|
- lib/web_translate_it/configuration.rb
|
62
|
+
- lib/web_translate_it/tasks.rb
|
43
63
|
- lib/web_translate_it/translation_file.rb
|
44
64
|
- lib/web_translate_it/util.rb
|
45
|
-
- lib/web_translate_it
|
46
|
-
|
65
|
+
- lib/web_translate_it.rb
|
66
|
+
- generators/webtranslateit/lib/insert_commands.rb
|
67
|
+
- generators/webtranslateit/templates/translation.yml
|
68
|
+
- generators/webtranslateit/webtranslateit_generator.rb
|
69
|
+
has_rdoc: true
|
47
70
|
homepage: https://webtranslateit.com
|
48
71
|
licenses: []
|
49
72
|
|
@@ -72,9 +95,11 @@ signing_key:
|
|
72
95
|
specification_version: 3
|
73
96
|
summary: Sync your translations between your Rails app and Web Translate It
|
74
97
|
test_files:
|
98
|
+
- spec/examples/config/translation.yml
|
99
|
+
- spec/examples/en.yml
|
75
100
|
- spec/spec.opts
|
76
101
|
- spec/spec_helper.rb
|
77
102
|
- spec/web_translate_it/configuration_spec.rb
|
78
103
|
- spec/web_translate_it/translation_file_spec.rb
|
79
|
-
- spec/
|
80
|
-
- spec/
|
104
|
+
- spec/web_translate_it/util_spec.rb
|
105
|
+
- spec/web_translate_it_spec.rb
|