web_translate_it 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +22 -0
- data/README.md +130 -0
- data/examples/locale.rb +12 -0
- data/history.md +38 -0
- data/lib/web_translate_it.rb +22 -0
- data/lib/web_translate_it/auto_fetch.rb +14 -0
- data/lib/web_translate_it/configuration.rb +35 -0
- data/lib/web_translate_it/tasks.rb +92 -0
- data/lib/web_translate_it/translation_file.rb +56 -0
- data/lib/web_translate_it/util.rb +29 -0
- data/spec/examples/config/translation.yml +15 -0
- data/spec/examples/en.yml +38 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/web_translate_it/configuration_spec.rb +31 -0
- data/spec/web_translate_it/translation_file_spec.rb +24 -0
- metadata +78 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2009-2010 Atelier Convivialité
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# Web Translate It for Ruby on Rails
|
2
|
+
|
3
|
+
This is a gem to integrate your app with [Web Translate It](https://webtranslateit.com).
|
4
|
+
|
5
|
+
This gem provides your app with:
|
6
|
+
|
7
|
+
* a set of 4 handy rake task to fetch your translations.
|
8
|
+
* a rack middleware to automatically fetch new translations from Web Translate It.
|
9
|
+
|
10
|
+
## First steps
|
11
|
+
|
12
|
+
* For each environment you want to use the gem, add to your config/environment/development.rb:
|
13
|
+
|
14
|
+
`config.gem 'web_translate_it', :version => '~> 1.4.0', :source => 'http://gemcutter.org'`
|
15
|
+
|
16
|
+
* Then, run:
|
17
|
+
|
18
|
+
`rake gems:install`
|
19
|
+
|
20
|
+
Web Translate It doesn’t to be unpacked.
|
21
|
+
|
22
|
+
* Add in your `Rakefile` to add Web Translate It’s rake tasks:
|
23
|
+
|
24
|
+
`require 'web_translate_it/tasks' rescue LoadError`
|
25
|
+
|
26
|
+
* Run:
|
27
|
+
|
28
|
+
`rake trans:config`
|
29
|
+
|
30
|
+
If it doesn’t exist already, it will create a `config/translation.yml` file that contains:
|
31
|
+
|
32
|
+
api_key: SECRET
|
33
|
+
ignore_locales: :en
|
34
|
+
wti_id1: config/locales/file1_[locale].yml
|
35
|
+
wti_id2: config/locales/file2_[locale].yml</pre>
|
36
|
+
|
37
|
+
`api_key` is the API key (or token) provided per project by Web Translate It.
|
38
|
+
|
39
|
+
`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.
|
40
|
+
|
41
|
+
`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.
|
42
|
+
|
43
|
+
`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`.
|
44
|
+
|
45
|
+
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.
|
46
|
+
|
47
|
+
### Rake tasks provided
|
48
|
+
|
49
|
+
The gem provides 4 rake tasks.
|
50
|
+
|
51
|
+
rake trans:fetch:all
|
52
|
+
|
53
|
+
Fetch the latest translations for all your files for all languages defined in Web Translate It’s interface, except for the languages set in `ignore_locales`.
|
54
|
+
|
55
|
+
rake trans:fetch[fr_FR]
|
56
|
+
|
57
|
+
Fetch the latest translations for all the languages defined in Web Translate It’s interface. It takes the locale name as a parameter
|
58
|
+
|
59
|
+
rake trans:send[fr_FR]
|
60
|
+
|
61
|
+
Updates the latest translations for all your files in a specific locale defined in Web Translate It’s interface.
|
62
|
+
|
63
|
+
rake trans:version
|
64
|
+
|
65
|
+
Display the gem version.
|
66
|
+
|
67
|
+
### Automatically fetch new language files
|
68
|
+
|
69
|
+
This is useful for translators on development and staging environment: you get the strings as soon as they are translated on Web Translate It, but you probably don’t want this on production for performance and reliability reasons.
|
70
|
+
|
71
|
+
#### Rails 2.3 and newer
|
72
|
+
|
73
|
+
Use the rack middleware!
|
74
|
+
|
75
|
+
* Before starting up anything, you need to have a rack middleware setup to assign the value of the current locale to
|
76
|
+
`I18n.locale`.
|
77
|
+
This is very much specific to your app, this is left as an exercise to the reader. You can inspire yourself from
|
78
|
+
Ryan Tomakyo’s [locale.rb](http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/locale.rb).
|
79
|
+
You can also find an example of a very simple middleware using the `locale` parameter in
|
80
|
+
`[examples/locale.rb](http://github.com/AtelierConvivialite/webtranslateit/blob/master/examples/locale.rb)`.
|
81
|
+
|
82
|
+
* The next step is to setup the `autofetch` middleware. Add in `config/environments/development.rb` and any other
|
83
|
+
environments you want to autofetch this line:
|
84
|
+
|
85
|
+
config.middleware.use "WebTranslateIt::AutoFetch"
|
86
|
+
|
87
|
+
* Restart your application, load a page. You should see this in the logs:
|
88
|
+
|
89
|
+
Looking for fr_FR translations...
|
90
|
+
Done. Response code: 200
|
91
|
+
|
92
|
+
* That’s it!
|
93
|
+
|
94
|
+
#### Rails older than 2.3 (works also for 2.3 and newer)
|
95
|
+
|
96
|
+
* Add the following lines in your `ApplicationController`:
|
97
|
+
|
98
|
+
<pre>before_filter :update_locale
|
99
|
+
|
100
|
+
def update_locale
|
101
|
+
begin
|
102
|
+
WebTranslateIt.fetch_translations
|
103
|
+
rescue Exception => e
|
104
|
+
puts "** Web Translate It raised an exception: " + e.message
|
105
|
+
end
|
106
|
+
end</pre>
|
107
|
+
|
108
|
+
* Restart your application for the changes to take effect. You should see something like this in the logs:
|
109
|
+
|
110
|
+
Looking for fr translations...
|
111
|
+
Done. Response code: 304
|
112
|
+
|
113
|
+
* That’s it!
|
114
|
+
|
115
|
+
## Supported Rails Versions
|
116
|
+
|
117
|
+
The gem currently has been tested against the following version of Rails:
|
118
|
+
|
119
|
+
* 2.3.4
|
120
|
+
* 2.3.5
|
121
|
+
|
122
|
+
Please open a discussion on [the support forum](https://webtranslateit.com/forum) if you're using a version of Rails that is not listed above and the gem is not working properly.
|
123
|
+
|
124
|
+
## What is Web Translate It anyway?
|
125
|
+
|
126
|
+
Web Translate It is a web-based software for translating websites and applications. Its API it affords you to translate on Web Translate It’s web interface and test your translations on your development or staging environment. This is really useful for translations to translate on a stable environment, while being able to test their work directly.
|
127
|
+
|
128
|
+
Take a look at the [tour page](https://webtranslateit.com/tour) and at our [plans](https://webtranslateit.com/plans). We have a 10-day free trial, so you can give it a try for free.
|
129
|
+
|
130
|
+
Released under the MIT License.
|
data/examples/locale.rb
ADDED
data/history.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
## Version 1.4.0 / 2010-01-06
|
2
|
+
|
3
|
+
* The plugin is now a gem
|
4
|
+
|
5
|
+
## Version 1.3.0 / 2010-01-05
|
6
|
+
|
7
|
+
* Add rack middleware to automatically fetch your translations
|
8
|
+
* Remove `autofetch` parameter in configuration file as it is better off to leave it to the user to
|
9
|
+
include the rack middleware in each environment file.
|
10
|
+
* Add example of rack middleware for setting up I18n.locale
|
11
|
+
|
12
|
+
## Version 1.2.1 / 2010-01-04
|
13
|
+
|
14
|
+
* Add some documentation
|
15
|
+
* More feedback on file upload
|
16
|
+
|
17
|
+
## Version 1.2 / 2010-01-04
|
18
|
+
|
19
|
+
* New: Ability to **update** language files via PUT requests. Upload brand new language files is not possible at the moment.
|
20
|
+
|
21
|
+
## Version 1.1.1 / 2010-01-04
|
22
|
+
|
23
|
+
* Fix: locales in exclude list are no longer autofetched when browsing the app in these locales.
|
24
|
+
|
25
|
+
## Version 1.1 / 2010-01-04
|
26
|
+
|
27
|
+
* Support for multi-files projects.
|
28
|
+
* Deprecate `rake translation:*` in favour of the shorter form `rake trans`.
|
29
|
+
* Add task `rake trans:fetch[en_US]` to fetch files locale by locale.
|
30
|
+
* Add task `rake trans:fetch:all` to fetch all the files for all locales defined in Web Translate It’s web interface.
|
31
|
+
|
32
|
+
## Version 1.0.0 / 2009-11-02
|
33
|
+
|
34
|
+
* Better support for exceptions.
|
35
|
+
|
36
|
+
## Version 0.9.0 / 2009-10-26
|
37
|
+
|
38
|
+
* First version, plugin only support download of strings. Strings upload will be available in a later version.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'web_translate_it', 'util')
|
2
|
+
require File.join(File.dirname(__FILE__), 'web_translate_it', 'configuration')
|
3
|
+
require File.join(File.dirname(__FILE__), 'web_translate_it', 'translation_file')
|
4
|
+
require File.join(File.dirname(__FILE__), 'web_translate_it', 'auto_fetch')
|
5
|
+
|
6
|
+
module WebTranslateIt
|
7
|
+
def self.version
|
8
|
+
hash = YAML.load_file File.join(File.dirname(__FILE__), '../version.yml')
|
9
|
+
[hash[:major], hash[:minor], hash[:patch]].join('.')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fetch_translations
|
13
|
+
config = Configuration.new
|
14
|
+
locale = I18n.locale.to_s
|
15
|
+
return if config.ignore_locales.include?(locale)
|
16
|
+
puts "Looking for #{locale} translations..."
|
17
|
+
config.files.each do |file|
|
18
|
+
response_code = file.fetch(locale)
|
19
|
+
puts "Done. Response code: #{response_code}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module WebTranslateIt
|
2
|
+
class Configuration
|
3
|
+
require 'yaml'
|
4
|
+
attr_accessor :api_key, :files, :ignore_locales
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
file = File.join(RAILS_ROOT, 'config', 'translation.yml')
|
8
|
+
configuration = YAML.load_file(file)
|
9
|
+
self.api_key = configuration['api_key']
|
10
|
+
self.files = []
|
11
|
+
self.ignore_locales = configuration['ignore_locales'].to_a.map{ |l| l.to_s }
|
12
|
+
configuration['files'].each do |file_id, file_path|
|
13
|
+
self.files.push(TranslationFile.new(file_id, file_path, api_key))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def locales
|
18
|
+
http = Net::HTTP.new('webtranslateit.com', 443)
|
19
|
+
http.use_ssl = true
|
20
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
21
|
+
http.read_timeout = 10
|
22
|
+
request = Net::HTTP::Get.new("/api/projects/#{api_key}/locales")
|
23
|
+
response = http.request(request)
|
24
|
+
response.body.split
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.generate
|
28
|
+
config_file = "config/translation.yml"
|
29
|
+
unless File.exists?(config_file)
|
30
|
+
puts "Creating #{config_file}"
|
31
|
+
File.cp File.join(File.dirname(__FILE__), 'examples', 'translation.yml'), config_file
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'web_translate_it')
|
2
|
+
|
3
|
+
namespace :trans do
|
4
|
+
desc "Fetch translation files from Web Translate It"
|
5
|
+
task :fetch, :locale do |t, args|
|
6
|
+
welcome_message
|
7
|
+
colour_puts "<b>Fetching file for locale #{args.locale}...</b>"
|
8
|
+
configuration = WebTranslateIt::Configuration.new
|
9
|
+
configuration.files.each do |file|
|
10
|
+
response_code = file.fetch(args.locale)
|
11
|
+
case response_code
|
12
|
+
when 200
|
13
|
+
colour_puts "<green>#{file.file_path_for_locale(args.locale)}: 200 OK. Saving changes</green>"
|
14
|
+
when 304
|
15
|
+
colour_puts "<green>#{file.file_path_for_locale(args.locale)}: 304 Not Modified</green>"
|
16
|
+
else
|
17
|
+
colour_puts "<red>#{file.file_path_for_locale(args.locale)}: Error, unhandled response: #{response_code}</red>"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :fetch do
|
23
|
+
desc "Fetch all the translation files from Web Translate It"
|
24
|
+
task :all do
|
25
|
+
welcome_message
|
26
|
+
configuration = WebTranslateIt::Configuration.new
|
27
|
+
locales = configuration.locales
|
28
|
+
configuration.ignore_locales.each do |ignore|
|
29
|
+
locales.delete(ignore)
|
30
|
+
end
|
31
|
+
colour_puts "<b>Fetching all files for all locales...</b>"
|
32
|
+
locales.each do |locale|
|
33
|
+
configuration.files.each do |file|
|
34
|
+
response_code = file.fetch(locale)
|
35
|
+
case response_code
|
36
|
+
when 200
|
37
|
+
colour_puts "<green>#{file.file_path_for_locale(locale)}: 200 OK.</green>"
|
38
|
+
when 304
|
39
|
+
colour_puts "<green>#{file.file_path_for_locale(locale)}: 304 Not Modified</green>"
|
40
|
+
else
|
41
|
+
colour_puts "<red>#{file.file_path_for_locale(locale)}: Error, unhandled response: #{response_code}</red>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Send a translation file to Web Translate It"
|
49
|
+
task :send, :locale do |t, args|
|
50
|
+
welcome_message
|
51
|
+
colour_puts "<b>Sending file for locale #{args.locale}...</b>"
|
52
|
+
configuration = WebTranslateIt::Configuration.new
|
53
|
+
configuration.files.each do |file|
|
54
|
+
response_code = file.send(args.locale)
|
55
|
+
case response_code
|
56
|
+
when 200
|
57
|
+
colour_puts "<green>#{file.file_path_for_locale(args.locale)} uploaded OK.</green>"
|
58
|
+
else
|
59
|
+
colour_puts "<red>#{file.file_path_for_locale(args.locale)}: Error uploading, unhandled response: #{response_code}</red>"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Install Web Translate It for your application"
|
65
|
+
task :config do
|
66
|
+
welcome_message
|
67
|
+
WebTranslateIt::Configuration.generate
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Output the Web Translate It gem version"
|
71
|
+
task :version do
|
72
|
+
welcome_message
|
73
|
+
colour_puts "Web Translate It gem for Ruby on Rails <b>v#{WebTranslateIt.version}</b>"
|
74
|
+
end
|
75
|
+
|
76
|
+
def welcome_message
|
77
|
+
colour_puts WELCOME_SCREEN
|
78
|
+
end
|
79
|
+
|
80
|
+
def colour_puts(text)
|
81
|
+
puts WebTranslateIt::Util.subs_colour(text)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
WELCOME_SCREEN = <<-EO_WELCOME
|
87
|
+
|
88
|
+
<banner>Web Translate It</banner>
|
89
|
+
|
90
|
+
EO_WELCOME
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module WebTranslateIt
|
2
|
+
class TranslationFile
|
3
|
+
require 'net/https'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
attr_accessor :id, :file_path, :api_key
|
7
|
+
|
8
|
+
def initialize(id, file_path, api_key)
|
9
|
+
self.id = id
|
10
|
+
self.file_path = file_path
|
11
|
+
self.api_key = api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(locale)
|
15
|
+
http = Net::HTTP.new('webtranslateit.com', 443)
|
16
|
+
http.use_ssl = true
|
17
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
18
|
+
http.read_timeout = 10
|
19
|
+
request = Net::HTTP::Get.new(api_url(locale))
|
20
|
+
|
21
|
+
if File.exist?(file_path_for_locale(locale))
|
22
|
+
request.add_field('If-Modified-Since', File.mtime(File.new(file_path_for_locale(locale), 'r')).rfc2822)
|
23
|
+
end
|
24
|
+
response = http.request(request)
|
25
|
+
response_code = response.code.to_i
|
26
|
+
|
27
|
+
if response_code == 200 and not response.body == ''
|
28
|
+
locale_file = File.new(file_path_for_locale(locale), 'w')
|
29
|
+
locale_file.puts(response.body)
|
30
|
+
locale_file.close
|
31
|
+
end
|
32
|
+
response_code
|
33
|
+
end
|
34
|
+
|
35
|
+
def send(locale)
|
36
|
+
File.open(file_path_for_locale(locale)) do |file|
|
37
|
+
http = Net::HTTP.new('webtranslateit.com', 443)
|
38
|
+
http.use_ssl = true
|
39
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
40
|
+
http.read_timeout = 10
|
41
|
+
|
42
|
+
request = Net::HTTP::Put::Multipart.new(api_url(locale), "file" => UploadIO.new(file, "text/plain", file.path))
|
43
|
+
response = http.request(request)
|
44
|
+
response.code.to_i
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def file_path_for_locale(locale)
|
49
|
+
self.file_path.gsub("[locale]", locale)
|
50
|
+
end
|
51
|
+
|
52
|
+
def api_url(locale)
|
53
|
+
"/api/projects/#{api_key}/files/#{self.id}/locales/#{locale}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WebTranslateIt
|
2
|
+
class Util
|
3
|
+
DEFAULT_TERMINAL_COLORS = "\e[0m\e[37m\e[40m"
|
4
|
+
MONOCHROME_OUTPUT = "\\1"
|
5
|
+
|
6
|
+
def self.colourise_output?
|
7
|
+
@colourise_output = !!(RUBY_PLATFORM !~ /mswin/ || defined?(Win32::Console::ANSI)) if @colourise_output.nil?
|
8
|
+
@colourise_output
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.subs_colour(data)
|
12
|
+
data = data.gsub(%r{<b>(.*?)</b>}m, colourise_output? ? "\e[1m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
|
13
|
+
data.gsub!(%r{<red>(.*?)</red>}m, colourise_output? ? "\e[1m\e[31m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
|
14
|
+
data.gsub!(%r{<green>(.*?)</green>}m, colourise_output? ? "\e[1m\e[32m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
|
15
|
+
data.gsub!(%r{<yellow>(.*?)</yellow>}m, colourise_output? ? "\e[1m\e[33m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
|
16
|
+
data.gsub!(%r{<banner>(.*?)</banner>}m, colourise_output? ? "\e[33m\e[44m\e[1m\\1#{DEFAULT_TERMINAL_COLORS}" : MONOCHROME_OUTPUT)
|
17
|
+
data
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.insert_into(file, line)
|
21
|
+
logger.insert "#{line} into #{file}"
|
22
|
+
unless options[:pretend] || file_contains?(file, line)
|
23
|
+
gsub_file file, /^(class|module) .+$/ do |match|
|
24
|
+
"#{match}\n #{line}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# The Project API Token from Web Translate It
|
2
|
+
api_key: abcd
|
3
|
+
|
4
|
+
# The Master locale is the locale you translate your project from. Web Translate It shouldn’t
|
5
|
+
# attempt to edit these files.
|
6
|
+
ignore_locales: en_GB
|
7
|
+
|
8
|
+
# A list of files to translate
|
9
|
+
# You can name your language files as you want, as long as the locale name match the
|
10
|
+
# locale name you set in Web Translate It, and that the different language files names are
|
11
|
+
# differenciated by their locale name.
|
12
|
+
# For example, if you set to translate a project in en_US in WTI, you should use the locale en_US in your app
|
13
|
+
files:
|
14
|
+
- config/locales/file1_[locale].yml
|
15
|
+
- config/locales/file2_[locale].yml
|
@@ -0,0 +1,38 @@
|
|
1
|
+
en:
|
2
|
+
activerecord:
|
3
|
+
errors:
|
4
|
+
templates:
|
5
|
+
header:
|
6
|
+
one: "1 error prohibited this {{model}} from being saved"
|
7
|
+
other: "{{count}} errors prohibited this {{model}} from being saved"
|
8
|
+
body: "there were problems with the following fields:"
|
9
|
+
messages:
|
10
|
+
accepted: "must be accepted"
|
11
|
+
blank: "can't be blank"
|
12
|
+
confirmation: "doesn't match confirmation"
|
13
|
+
empty: "can't be empty"
|
14
|
+
equal_to: "must be equal to {{count}}"
|
15
|
+
even: "must be even"
|
16
|
+
exclusion: "is reserved"
|
17
|
+
greater_than: "must be greater than {{count}}"
|
18
|
+
greater_than_or_equal_to: "must be greater than or equal to {{count}}"
|
19
|
+
inclusion: "is not included in the list"
|
20
|
+
invalid: "is invalid"
|
21
|
+
less_than: "must be less than {{count}}"
|
22
|
+
less_than_or_equal_to: "must be less than or equal to {{count}}"
|
23
|
+
not_a_number: "is not a number"
|
24
|
+
odd: "must be odd"
|
25
|
+
taken: "is already taken"
|
26
|
+
too_long: "is too long (maximum is {{count}} characters)"
|
27
|
+
too_short: "is too short (minimum is {{count}} characters)"
|
28
|
+
wrong_length: "is the wrong length (should be {{count}} characters)"
|
29
|
+
models:
|
30
|
+
invitation:
|
31
|
+
attributes:
|
32
|
+
email:
|
33
|
+
user_already_invited: "This user has already been invited"
|
34
|
+
user_already_member: "This user is already a member"
|
35
|
+
project_file:
|
36
|
+
attributes:
|
37
|
+
file:
|
38
|
+
file_format_not_supported: "Sorry, we currenly support only Gettext .pot/.po, .yml/.yaml and .strings"
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe WebTranslateIt::Configuration do
|
4
|
+
before(:each) do
|
5
|
+
WebTranslateIt::Configuration.const_set("RAILS_ROOT", File.dirname(__FILE__) + '/../examples')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#initialize" do
|
9
|
+
it "should fetch and not blow up" do
|
10
|
+
lambda{ WebTranslateIt::Configuration.new }.should_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should load the content of the YAML file" do
|
14
|
+
config_hash = {
|
15
|
+
"api_key" => "abcd",
|
16
|
+
"ignore_locales" => "en_GB",
|
17
|
+
"files" => ["config/locales/file1_[locale].yml", "config/locales/file2_[locale].yml"]
|
18
|
+
}
|
19
|
+
YAML.should_receive(:load_file).and_return(config_hash)
|
20
|
+
WebTranslateIt::Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should assign the API key, autofetch, files and master_locale" do
|
24
|
+
configuration = WebTranslateIt::Configuration.new
|
25
|
+
configuration.api_key.should == 'abcd'
|
26
|
+
configuration.files.first.should be_a(WebTranslateIt::TranslationFile)
|
27
|
+
configuration.ignore_locales.should == ['en_GB']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe WebTranslateIt::TranslationFile do
|
4
|
+
before(:each) do
|
5
|
+
@translation_file = WebTranslateIt::TranslationFile.new(1174, "/config/locales/[locale].yml", "04b254da22a6eb301b103f848e469ad494eea47d")
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#fetch" do
|
9
|
+
it "should prepare a HTTP request and get a 200 OK if the language file is stale" do
|
10
|
+
file = mock(File)
|
11
|
+
file.stub(:puts => true, :close => true)
|
12
|
+
File.stub(:exist? => true, :mtime => Time.at(0), :new => file)
|
13
|
+
@translation_file.fetch('fr_FR').should == 200
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should prepare a HTTP request and get a 304 OK if the language file is fresh" do
|
17
|
+
file = mock(File)
|
18
|
+
file.stub(:puts => true, :close => true)
|
19
|
+
File.stub(:exist? => true, :mtime => Time.now, :new => file)
|
20
|
+
@translation_file.stub(:path_to_locale_file => file)
|
21
|
+
@translation_file.fetch('fr_FR').should == 304
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: web_translate_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "\xC3\x89douard Bri\xC3\xA8re"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-06 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: multipart-post
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.0"
|
24
|
+
version:
|
25
|
+
description: Ruby on Rails plugin and rack middleware to sync your translations between webtranslateit.com and your rails applications.
|
26
|
+
email: edouard@atelierconvivialite.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- history.md
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- examples/locale.rb
|
38
|
+
- lib/web_translate_it.rb
|
39
|
+
- lib/web_translate_it/auto_fetch.rb
|
40
|
+
- lib/web_translate_it/configuration.rb
|
41
|
+
- lib/web_translate_it/translation_file.rb
|
42
|
+
- lib/web_translate_it/util.rb
|
43
|
+
- lib/web_translate_it/tasks.rb
|
44
|
+
has_rdoc: false
|
45
|
+
homepage: https://webtranslateit.com
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Sync your translations between your Rails app and Web Translate It
|
72
|
+
test_files:
|
73
|
+
- spec/spec.opts
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/web_translate_it/configuration_spec.rb
|
76
|
+
- spec/web_translate_it/translation_file_spec.rb
|
77
|
+
- spec/examples/en.yml
|
78
|
+
- spec/examples/config/translation.yml
|