rack-webtranslateit 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -3
- data/lib/rack/webtranslateit.rb +5 -2
- data/lib/rack/webtranslateit/configuration.rb +6 -4
- data/templates/index.erb +1 -1
- metadata +1 -1
data/README.markdown
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
![rack-webtranslateit](http://s3.amazonaws.com:80/edouard.baconfile.com/rack-webtranslateit.png)
|
2
|
+
|
3
|
+
# Usage:
|
2
4
|
|
3
5
|
* Sign up for a webtranslateit.com premium account.
|
4
6
|
* Create a config/translation.yml file:
|
@@ -9,7 +11,7 @@
|
|
9
11
|
# The locales not to sync with Web Translate It.
|
10
12
|
# Pass an array of string, or an array of symbols, a string or a symbol.
|
11
13
|
# eg. [:en, :fr] or just 'en'
|
12
|
-
|
14
|
+
master_locale: :en
|
13
15
|
|
14
16
|
# A list of files to translate
|
15
17
|
# You can name your language files as you want, as long as the locale name match the
|
@@ -26,7 +28,7 @@
|
|
26
28
|
|
27
29
|
* Add the middleware:
|
28
30
|
|
29
|
-
config.gem 'rack-webtranslateit', :lib =>
|
31
|
+
config.gem 'rack-webtranslateit', :lib => 'rack/webtranslateit'
|
30
32
|
config.middleware.use "Rack::Webtranslateit", "/translations/"
|
31
33
|
|
32
34
|
* Go to http://yourapp/translations.
|
data/lib/rack/webtranslateit.rb
CHANGED
@@ -2,9 +2,12 @@ require "rack"
|
|
2
2
|
|
3
3
|
module Rack::Webtranslateit
|
4
4
|
def new(app, mount_point = "/translations/")
|
5
|
+
authenticator = method(:authenticator)
|
5
6
|
builder = Rack::Builder.new
|
6
|
-
builder.
|
7
|
-
|
7
|
+
builder.map(mount_point) do
|
8
|
+
use Rack::Auth::Basic, &authenticator if Configuration.password
|
9
|
+
run Ui.new
|
10
|
+
end
|
8
11
|
builder.map("/"){ run app }
|
9
12
|
builder.to_app
|
10
13
|
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
class Rack::Webtranslateit::Configuration
|
4
|
-
attr_accessor :api_key, :
|
4
|
+
attr_accessor :api_key, :files, :master_locale, :password
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
|
7
|
+
root = defined?(RAILS_ROOT) && RAILS_ROOT
|
8
|
+
root ||= defined?(RACK_ROOT) && RACK_ROOT
|
9
|
+
root ||= File.expand_path(".")
|
10
|
+
file = File.join(root, 'config', 'translation.yml')
|
8
11
|
configuration = YAML.load_file(file)
|
9
12
|
self.api_key = configuration['api_key']
|
10
|
-
self.autofetch = configuration[RAILS_ENV]['autofetch']
|
11
13
|
self.password = configuration['password']
|
14
|
+
self.master_locale = configuration['master_locale'].to_s
|
12
15
|
self.files = []
|
13
|
-
self.ignore_locales = [configuration['ignore_locales']].flatten.map{ |l| l.to_s }
|
14
16
|
configuration['files'].each do |file_id, file_path|
|
15
17
|
self.files.push(Rack::Webtranslateit::TranslationFile.new(file_id, file_path, api_key))
|
16
18
|
end
|
data/templates/index.erb
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
</div>
|
47
47
|
</div>
|
48
48
|
<div id="footer">
|
49
|
-
<p>This page was generated by <a href="">webtranslateit
|
49
|
+
<p>This page was generated by <a href="http://github.com/cwninja/rack-webtranslateit">rack-webtranslateit</a>, developed by <a href="http://tomlea.co.uk">Tom Lea</a> at <a href="http://www.reevoo.com/">reevoo.com</a>.</p>
|
50
50
|
</div>
|
51
51
|
</body>
|
52
52
|
</html>
|