tr8n_client_sdk 4.1.6 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +147 -65
- data/Rakefile +31 -0
- data/{lib/tasks/tr8n_client_sdk.rake → app/controllers/tr8n_client_sdk/cache_controller.rb} +7 -15
- data/app/views/tr8n_client_sdk/tags/_language_selector.html.erb +2 -2
- data/app/views/tr8n_client_sdk/tags/_powered_by_tr8n.html.erb +15 -3
- data/app/views/tr8n_client_sdk/tags/_scripts.html.erb +33 -78
- data/config/routes.rb +33 -1
- data/lib/i18n/backend/tr8n.rb +62 -0
- data/lib/tasks/tr8n.rake +60 -0
- data/lib/tr8n/cache_adapters/rails.rb +2 -4
- data/lib/tr8n_client_sdk/core/string.rb +1 -1
- data/lib/tr8n_client_sdk/engine.rb +1 -1
- data/lib/tr8n_client_sdk/extensions/action_common_methods.rb +8 -8
- data/lib/tr8n_client_sdk/extensions/action_controller_extension.rb +13 -42
- data/lib/tr8n_client_sdk/extensions/action_view_extension.rb +3 -4
- data/lib/tr8n_client_sdk/railtie.rb +1 -1
- data/lib/tr8n_client_sdk/version.rb +2 -2
- data/lib/tr8n_client_sdk.rb +2 -1
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2c5d0fc6b0b1a8f19a0c1d744e67421eef4c2ba
|
4
|
+
data.tar.gz: c30856b2d4f36db9dfafdfa04cc835519858b4fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea75b84daa691897516b52147b90f20df8cb5239d7ef58ebe198d09deb4f8d3669f813740232c8b1ad33784f67764213d9a0d3da566bc2bcfec0349177f8c1d
|
7
|
+
data.tar.gz: de278681dbd09b56b8d23f440456996a3c7fb2df4ee776818d1bc70a0587f7d2bdaa9b41edcb4b843749bee5ea3f5cddf6d70611fe2d9efbfb2b07c126c56c94
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,84 +2,75 @@
|
|
2
2
|
<img src="https://raw.github.com/tr8n/tr8n/master/doc/screenshots/tr8nlogo.png">
|
3
3
|
</p>
|
4
4
|
|
5
|
-
Tr8n
|
5
|
+
Tr8n SDK for Ruby on Rails
|
6
6
|
===================================
|
7
7
|
[![Build Status](https://travis-ci.org/tr8n/tr8n_rails_clientsdk.png?branch=master)](https://travis-ci.org/tr8n/tr8n_rails_clientsdk)
|
8
8
|
[![Coverage Status](https://coveralls.io/repos/tr8n/tr8n_rails_clientsdk/badge.png)](https://coveralls.io/r/tr8n/tr8n_rails_clientsdk)
|
9
9
|
[![Gem Version](https://badge.fury.io/rb/tr8n_client_sdk.png)](http://badge.fury.io/rb/tr8n_client_sdk)
|
10
10
|
[![Dependency Status](https://www.versioneye.com/user/projects/53cda6a5225426f1e8000165/badge.svg?style=flat)](https://www.versioneye.com/user/projects/53cda6a5225426f1e8000165)
|
11
|
-
[![Project status](http://stillmaintained.com/tr8n/tr8n_ruby_core.png)](http://stillmaintained.com/tr8n/tr8n_ruby_core.png)
|
12
11
|
|
13
|
-
This Client SDK provides
|
12
|
+
This Client SDK provides tools for translating Rails applications into any language using the TranslationExchange.com service.
|
14
13
|
|
15
14
|
|
16
|
-
|
15
|
+
Installation
|
17
16
|
===================================
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
```sh
|
22
|
-
$ git clone https://github.com/tr8n/tr8n_rails_clientsdk.git
|
23
|
-
$ cd tr8n_rails_clientsdk/spec/dummy
|
24
|
-
$ bundle
|
25
|
-
```
|
26
|
-
|
27
|
-
Before you running the application, visit TranslationExchange.com, register as a new user and create a new application.
|
18
|
+
To integrate Tr8n SDK into your own application, all you need to do is:
|
28
19
|
|
29
|
-
|
20
|
+
Add the following gem to your Gemfile:
|
30
21
|
|
31
22
|
```ruby
|
32
|
-
|
33
|
-
:key => YOUR_KEY,
|
34
|
-
:secret => YOUR_SECRET
|
35
|
-
}
|
23
|
+
gem 'tr8n_client_sdk'
|
36
24
|
```
|
37
25
|
|
38
|
-
|
26
|
+
Install the gems:
|
39
27
|
|
40
28
|
```sh
|
41
|
-
$ bundle
|
29
|
+
$ bundle
|
42
30
|
```
|
43
31
|
|
44
32
|
|
45
|
-
|
46
|
-
|
47
|
-
http://localhost:3000
|
33
|
+
Configuration
|
34
|
+
===================================
|
48
35
|
|
36
|
+
Create a tr8n initializer file with the following configuration:
|
49
37
|
|
38
|
+
config/initializers/tr8n.rb
|
50
39
|
|
40
|
+
```ruby
|
41
|
+
Tr8n.configure do |config|
|
42
|
+
config.application = {
|
43
|
+
:key => YOUR_APP_KEY,
|
44
|
+
:secret => YOUR_APP_SECRET
|
45
|
+
}
|
46
|
+
end
|
47
|
+
```
|
51
48
|
|
52
|
-
|
53
|
-
===================================
|
49
|
+
Tr8n should be run with caching enabled. You can specify the cache you want to use by providing it in the initializer.
|
54
50
|
|
55
|
-
|
51
|
+
If you are already using Rails caching, you can use it for Tr8n as well:
|
56
52
|
|
57
|
-
|
53
|
+
config/environments/production.rb
|
58
54
|
|
59
55
|
```ruby
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
Install the gems:
|
56
|
+
config.cache_store = :mem_cache_store, Dalli::Client.new('localhost:11211', {:namespace => 'myapplication'})
|
57
|
+
config.identity_cache_store = :mem_cache_store, Dalli::Client.new('localhost:11211', {:namespace => 'myapplication'})
|
64
58
|
|
65
|
-
```sh
|
66
|
-
$ bundle
|
67
59
|
```
|
68
60
|
|
69
|
-
|
61
|
+
config/initializers/tr8n.rb
|
70
62
|
|
71
63
|
```ruby
|
72
64
|
Tr8n.configure do |config|
|
73
|
-
config.
|
74
|
-
|
75
|
-
|
65
|
+
config.cache = {
|
66
|
+
:enabled => true,
|
67
|
+
:adapter => 'rails',
|
68
|
+
:version => 1
|
76
69
|
}
|
77
70
|
end
|
78
71
|
```
|
79
72
|
|
80
|
-
|
81
|
-
|
82
|
-
Memcache example:
|
73
|
+
Alternatively, you can provide a separate memcache server specifically for translations:
|
83
74
|
|
84
75
|
```ruby
|
85
76
|
Tr8n.configure do |config|
|
@@ -93,7 +84,7 @@ Memcache example:
|
|
93
84
|
end
|
94
85
|
```
|
95
86
|
|
96
|
-
Redis
|
87
|
+
You can also use Redis to persist your translations cache:
|
97
88
|
|
98
89
|
```ruby
|
99
90
|
Tr8n.configure do |config|
|
@@ -107,8 +98,51 @@ Redis example:
|
|
107
98
|
end
|
108
99
|
```
|
109
100
|
|
110
|
-
|
101
|
+
The above examples use shared caching model - all your Rails processes on all your servers share the same translation cache. This approach
|
102
|
+
will save you memory space, as well as allow you to invalidate/redeploy your translations cache without having to redeploy your application.
|
111
103
|
|
104
|
+
To update the cache, run the following line of code from any application instance (for example, an admin tool):
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
Tr8n.cache.upgrade_version
|
108
|
+
```
|
109
|
+
|
110
|
+
Or you can run the rake command:
|
111
|
+
|
112
|
+
```sh
|
113
|
+
$ bundle exec rake tr8n:cache:upgrade
|
114
|
+
```
|
115
|
+
|
116
|
+
This will effectively invalidate your current cache and rebuilt it with the latest translations from Translation Exchange's CDN.
|
117
|
+
|
118
|
+
An alternative approach is to pre-generate all your cache files when you deploy your application. The translation cache will be loaded and stored in every process on every server,
|
119
|
+
but it will be faster at serving translations and this approach does not require cache warmup.
|
120
|
+
|
121
|
+
If you prefer to use in-memory caching, you can specify the file based cache using:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
Tr8n.configure do |config|
|
125
|
+
config.cache = {
|
126
|
+
:enabled => true,
|
127
|
+
:adapter => 'file',
|
128
|
+
:path => 'config/tr8n',
|
129
|
+
:version => 'current',
|
130
|
+
:segmented => false
|
131
|
+
}
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
If you set ':segmented' to 'true' it will generate cache files per language per source, instead of one file per language for the entire application.
|
136
|
+
|
137
|
+
The file based cache must be generated before you deploy your application using the following command:
|
138
|
+
|
139
|
+
```sh
|
140
|
+
$ bundle exec rake tr8n:cache:generate
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
Integration
|
145
|
+
===================================
|
112
146
|
|
113
147
|
In the HEAD section of your layout, add:
|
114
148
|
|
@@ -129,7 +163,7 @@ server, but it may not be ideal on production. There are a number of alternative
|
|
129
163
|
|
130
164
|
To use a dropdown language selector that uses locale in the url parameter, use:
|
131
165
|
|
132
|
-
```
|
166
|
+
```ruby
|
133
167
|
<%= tr8n_language_selector_tag(
|
134
168
|
:type => :dropdown,
|
135
169
|
:style => "margin-top:15px",
|
@@ -137,16 +171,13 @@ To use a dropdown language selector that uses locale in the url parameter, use:
|
|
137
171
|
) %>
|
138
172
|
```
|
139
173
|
|
140
|
-
|
141
|
-
of the language name or have the language be printed in a native language.
|
142
|
-
|
143
|
-
|
144
|
-
Now you can use TML (Translation Markup Language) in your application to translate your strings:
|
174
|
+
Now you can use Tr8n's helper methods and TML (Translation Markup Language) to translate your strings:
|
145
175
|
|
146
|
-
```
|
176
|
+
```ruby
|
147
177
|
<%= tr("Hello World") %>
|
148
|
-
<%= tr("You have {count||message}", :
|
149
|
-
<%= tr("{actor} sent {target} [bold: {count||gift}]", :
|
178
|
+
<%= tr("You have {count || message}", count: 5) %>
|
179
|
+
<%= tr("{actor} sent {target} [bold: {count || gift}]", actor: actor_user, target: target_user, count: 5) %>
|
180
|
+
<%= tr("{actor} uploaded [bold: {count || photo}] to {actor | his, her} photo album.", actor: current_user, count: 5) %>
|
150
181
|
...
|
151
182
|
```
|
152
183
|
|
@@ -159,29 +190,48 @@ you can simply use:
|
|
159
190
|
|
160
191
|
```
|
161
192
|
|
162
|
-
|
163
|
-
Learn more about TML at: https://TranslationExchange.com/docs
|
193
|
+
Learn more about TML at: http://TranslationExchange.com/docs
|
164
194
|
|
165
195
|
|
166
|
-
|
196
|
+
I18n fallback
|
167
197
|
===================================
|
168
198
|
|
169
|
-
|
199
|
+
If your application is already using the standard i18n framework, you can mix in the Tr8n framework on top of it. To do so,
|
200
|
+
you need to set the i18n backend to Tr8n. Add the following line to your tr8n initializer:
|
201
|
+
|
202
|
+
config/initializers/tr8n.rb
|
170
203
|
|
171
204
|
```ruby
|
172
|
-
Tr8n.
|
205
|
+
I18n.backend = I18n::Backend::Tr8n.new
|
173
206
|
```
|
174
207
|
|
175
|
-
|
208
|
+
Now the "t" function will automatically fallback onto "tr" function. If you have the following in your base language file:
|
176
209
|
|
210
|
+
config/locales/en.yml
|
177
211
|
|
178
|
-
|
212
|
+
```ruby
|
213
|
+
en:
|
214
|
+
hello: "Hello world"
|
215
|
+
my:
|
216
|
+
nested:
|
217
|
+
key: "This is a nested key"
|
218
|
+
```
|
179
219
|
|
180
|
-
|
181
|
-
|
220
|
+
Then you can call:
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
<%= t(:hello) %>
|
224
|
+
<%= t("my.nested.key") %>
|
182
225
|
```
|
183
226
|
|
184
|
-
|
227
|
+
And the i18n will use Translation Exchange as the backend for your translations. On top of it, you can continue using Tr8n's extensions:
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
<%= tr("Hello World") %>
|
231
|
+
<%= tr("This is a nested key") %>
|
232
|
+
```
|
233
|
+
|
234
|
+
The above calls are equivalent.
|
185
235
|
|
186
236
|
|
187
237
|
Logging
|
@@ -232,20 +282,52 @@ If you need to adjust those method names, you can set them in the config:
|
|
232
282
|
```
|
233
283
|
|
234
284
|
|
285
|
+
Tr8n Client SDK Sample
|
286
|
+
===================================
|
287
|
+
|
288
|
+
The best way to start using the SDK is to run a sample application that comes bundled with this SDK.
|
289
|
+
|
290
|
+
```sh
|
291
|
+
$ git clone https://github.com/tr8n/tr8n_rails_clientsdk.git
|
292
|
+
$ cd tr8n_rails_clientsdk/spec/dummy
|
293
|
+
$ bundle
|
294
|
+
```
|
295
|
+
|
296
|
+
Before you running the application, visit TranslationExchange.com, register as a new user and create a new application.
|
297
|
+
|
298
|
+
Update your key and secret in the following file: config/initializers/tr8n.rb
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
config.application = {
|
302
|
+
:key => YOUR_KEY,
|
303
|
+
:secret => YOUR_SECRET
|
304
|
+
}
|
305
|
+
```
|
306
|
+
|
307
|
+
Now you can start the application by running:
|
308
|
+
|
309
|
+
```sh
|
310
|
+
$ bundle exec rails s
|
311
|
+
```
|
312
|
+
|
313
|
+
|
314
|
+
This will start the dummy application on port 3000. Open your browser and point to:
|
315
|
+
|
316
|
+
http://localhost:3000
|
317
|
+
|
318
|
+
|
235
319
|
Links
|
236
320
|
==================
|
237
321
|
|
238
322
|
* Register on TranslationExchange.com: https://translationexchange.com
|
239
323
|
|
240
|
-
* Read TranslationExchange's documentation:
|
241
|
-
|
242
|
-
* Visit TranslationExchange's blog: http://blog.translationexchange.com
|
324
|
+
* Read TranslationExchange's documentation: https://translationexchange.com/docs
|
243
325
|
|
244
326
|
* Follow TranslationExchange on Twitter: https://twitter.com/translationx
|
245
327
|
|
246
328
|
* Connect with TranslationExchange on Facebook: https://www.facebook.com/translationexchange
|
247
329
|
|
248
|
-
* If you have any questions or suggestions, contact us:
|
330
|
+
* If you have any questions or suggestions, contact us: feedback@translationexchange.com
|
249
331
|
|
250
332
|
|
251
333
|
Copyright and license
|
data/Rakefile
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
|
+
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
|
1
32
|
#!/usr/bin/env rake
|
2
33
|
#begin
|
3
34
|
# require 'bundler/setup'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
4
|
# _______ _ _ _ ______ _
|
5
5
|
# |__ __| | | | | (_) | ____| | |
|
@@ -29,19 +29,11 @@
|
|
29
29
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
30
|
#++
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
module Tr8nClientSdk
|
33
|
+
class CacheController < ApplicationController
|
34
|
+
def upgrade
|
35
|
+
Tr8n.cache.upgrade_version
|
36
|
+
redirect_to(request.env['HTTP_REFERER'] || '/')
|
37
|
+
end
|
36
38
|
end
|
37
|
-
|
38
|
-
task :cache do
|
39
|
-
require "tr8n_client_sdk/config"
|
40
|
-
Tr8n.config = Tr8nClientSdk::Config.new
|
41
|
-
|
42
|
-
Tr8n.config.init_application
|
43
|
-
g = Tr8nCore::Generators::Cache::File.new
|
44
|
-
g.run
|
45
|
-
end
|
46
|
-
|
47
39
|
end
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<% elsif opts[:language] == :english %>
|
32
32
|
<%= lang.english_name %>
|
33
33
|
<% else %>
|
34
|
-
<%= lang.
|
34
|
+
<%= lang.english_name %>
|
35
35
|
<% end %>
|
36
36
|
</option>
|
37
37
|
<% end %>
|
@@ -47,7 +47,7 @@
|
|
47
47
|
<% elsif opts[:language] == :english %>
|
48
48
|
<%= tr8n_current_language.english_name %>
|
49
49
|
<% else %>
|
50
|
-
<%= tr8n_current_language.
|
50
|
+
<%= tr8n_current_language.english_name %>
|
51
51
|
<% end %>
|
52
52
|
</a>
|
53
53
|
<% end %>
|
@@ -1,6 +1,18 @@
|
|
1
1
|
<div style="padding-top:40px; color: #ccc; text-align:center; width:100%">
|
2
|
-
<%= tr("Powered by {
|
3
|
-
|
4
|
-
|
2
|
+
<%= tr("Powered by {trex}", :trex => link_to("TranslationExchange.com", "http://translationexchange.com", :style=>"color:#ccc;")) %>
|
3
|
+
|
4
|
+
<style>
|
5
|
+
.trex_logo {
|
6
|
+
margin-top:10px;
|
7
|
+
padding: 40px;
|
8
|
+
background-repeat: no-repeat;
|
9
|
+
background-image:url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABQCAYAAABCiMhGAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCQTg4MTEyOEU0NkIxMUUzODhCMEJEOUNDRDQ0QkU0MiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCQTg4MTEyOUU0NkIxMUUzODhCMEJEOUNDRDQ0QkU0MiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkJBODgxMTI2RTQ2QjExRTM4OEIwQkQ5Q0NENDRCRTQyIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkJBODgxMTI3RTQ2QjExRTM4OEIwQkQ5Q0NENDRCRTQyIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+mszKSAAAAqFJREFUeNrsnE1IFVEYhr+53QiKEIkgpCBwJSH9SITkqkVELXJZ0iYIqRaBCZWgoWKikRBI1KVNmyg3gVKQ0CZE+9kHQYukaGP2I6iEP1ffc+dc7iwK5s5Mx3PPvC88zGxm5s4zc85853JmvNardwTxwC1wGuyWdGQGvARduaH23wUJkJHFcgoclnTmKzgIIT8yWOlNsQiVPeB+8c74hmWNMNXqzqimh0JqlIxVeigkr2Tk6aGQtQwdlEIZlEEZlEEZEZONuf0YmASLYNNGPRI1e8FFsHUjZNwAg5Zd3GHwHuw02Uw+WShCZRr0m+4zPljc9D+alpG1WMYW0zJsfgplxMGTYp1BGZRBGZRBGZRBGZRBGZRBGZRBGQxlUAZlUAZlUAZlUAZlUAZlUAZlUIbDMmyeYr3KO6OUJdMyGiyWcdS0DPV+ykMLRRwD16JuHGc60gV9Fd6KP/Vxs/hTEDvBbIT9nQLNEdp8XkpTH0/GMRl3bladJpi7EWQcB89dfLSW24EdAeOsM0T2gQkWXX4bf6P7mlTL2KFFbE97Ob4NvAO70j42UcdTbyHU2jo28Qwe7zXYb2nl6mXE3DzwF6DJ5kGrkjFv4EBP4laHBjKjZDz7zwfJgTOWi3iVG2qfVTKui//ZhMTaXmD9Hmi1XMSf4m9UMubAIfAY/Epg58t62QcuWyxhQfx37A7grvgcHKipgdU5UPWX538LuBlh8Deu+4oVS2X8BN8h4p+j1jlNMOW+5lQ8+QmpsIQpusr5vsYV8EUqNElWoKojHpYKTlIyusFtqfAkIWMA9IgDiStD/cXXIY4kjowHoE0cSlQZj8AlcSxRZDwF58XBhJGxFlgfBWfF0YSR4QXK62ZxOGFk1OtR7QlxPGFkjIBGSUHWBRgAlJNpO4bVinwAAAAASUVORK5CYII=);
|
10
|
+
}
|
11
|
+
</style>
|
12
|
+
|
13
|
+
<div style="text-align: center">
|
14
|
+
<%=link_to('http://translationexchange.com') do %>
|
15
|
+
<img class="trex_logo" src="" alt="" />
|
16
|
+
<% end %>
|
5
17
|
</div>
|
6
18
|
</div>
|
@@ -1,90 +1,45 @@
|
|
1
1
|
<% if Tr8n.config.enabled? %>
|
2
|
-
|
3
2
|
<style type="text/css">
|
4
|
-
|
5
|
-
<%=tr8n_style_attribute_tag('float', '
|
6
|
-
|
7
|
-
|
8
|
-
<%=tr8n_style_attribute_tag('float', 'left')%> !important;
|
9
|
-
}
|
10
|
-
.tr8n_txtr {
|
11
|
-
<%=tr8n_style_attribute_tag('text-align', 'right')%> !important;
|
12
|
-
}
|
13
|
-
.tr8n_txtl {
|
14
|
-
<%=tr8n_style_attribute_tag('text-align', 'left')%> !important;
|
15
|
-
}
|
3
|
+
.tr8n_fltr {<%=tr8n_style_attribute_tag('float', 'right')%> !important;}
|
4
|
+
.tr8n_fltl {<%=tr8n_style_attribute_tag('float', 'left')%> !important;}
|
5
|
+
.tr8n_txtr {<%=tr8n_style_attribute_tag('text-align', 'right')%> !important;}
|
6
|
+
.tr8n_txtl {<%=tr8n_style_attribute_tag('text-align', 'left')%> !important;}
|
16
7
|
</style>
|
17
8
|
|
18
9
|
<script>
|
19
|
-
function
|
20
|
-
|
21
|
-
|
22
|
-
css = doc.createElement('style'); css.type = 'text/css';
|
23
|
-
if (css.styleSheet) css.styleSheet.cssText = value;
|
24
|
-
else css.appendChild(document.createTextNode(value));
|
25
|
-
} else {
|
26
|
-
css = doc.createElement('link'); css.setAttribute('type', 'text/css');
|
27
|
-
css.setAttribute('rel', 'stylesheet'); css.setAttribute('media', 'screen');
|
28
|
-
if (value.indexOf('//') != -1) css.setAttribute('href', value);
|
29
|
-
else css.setAttribute('href', '<%= tr8n_application.host %>' + value);
|
30
|
-
}
|
31
|
-
doc.getElementsByTagName('head')[0].appendChild(css);
|
32
|
-
return css;
|
33
|
-
}
|
10
|
+
(function() {
|
11
|
+
if (window.tr8n_already_initialized) return;
|
12
|
+
window.tr8n_already_initialized = true;
|
34
13
|
|
35
|
-
|
36
|
-
|
37
|
-
script.setAttribute('id', id);
|
14
|
+
var script = window.document.createElement('script');
|
15
|
+
script.setAttribute('id', 'tr8n-tools');
|
38
16
|
script.setAttribute('type', 'application/javascript');
|
39
|
-
|
40
|
-
else script.setAttribute('src', '<%= tr8n_application.host %>' + src);
|
17
|
+
script.setAttribute('src', '<%= tr8n_application.tools['javascript'] %>');
|
41
18
|
script.setAttribute('charset', 'UTF-8');
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if (window.tr8n_already_initialized) return;
|
56
|
-
window.tr8n_already_initialized = true;
|
57
|
-
|
58
|
-
tr8n_add_css(window.document, '/assets/tr8n/tools.css', false);
|
59
|
-
tr8n_add_css(window.document, "<%= tr8n_application.css %>", true);
|
60
|
-
|
61
|
-
tr8n_add_script(window.document, 'tr8n-jssdk', '/assets/tools.js?t=<%=Time.now%>', function() {
|
62
|
-
Tr8n.app_key = '<%= tr8n_application.key %>';
|
63
|
-
Tr8n.host = '<%= tr8n_application.host %>';
|
64
|
-
Tr8n.sources = [];
|
65
|
-
Tr8n.default_locale = '<%= tr8n_application.default_locale %>';
|
66
|
-
Tr8n.page_locale = '<%= tr8n_current_language.locale %>';
|
67
|
-
Tr8n.locale = '<%= tr8n_current_language.locale %>';
|
68
|
-
|
69
|
-
<%
|
70
|
-
if tr8n_application.feature_enabled?(:shortcuts)
|
71
|
-
tr8n_application.shortcuts.each do |key, script|
|
72
|
-
%>
|
73
|
-
shortcut.add('<%=key.html_safe%>', function() {
|
74
|
-
<%= script.html_safe %>
|
75
|
-
});
|
76
|
-
<%
|
77
|
-
end
|
78
|
-
end
|
79
|
-
%>
|
80
|
-
|
81
|
-
if (typeof(tr8n_on_ready) === 'function') {
|
82
|
-
tr8n_on_ready();
|
83
|
-
}
|
19
|
+
script.onload = function() {
|
20
|
+
Tr8n.Utils.insertCSS(window.document, "<%= tr8n_application.tools['stylesheet'] %>", false);
|
21
|
+
Tr8n.Utils.insertCSS(window.document, "<%= tr8n_application.css %>", true);
|
22
|
+
Tr8n.app_key = '<%= tr8n_application.key %>';
|
23
|
+
Tr8n.host = '<%= tr8n_application.tools['host'] %>';
|
24
|
+
Tr8n.locale = '<%= tr8n_current_language.locale %>';
|
25
|
+
Tr8n.sources = [];
|
26
|
+
<%
|
27
|
+
if tr8n_application.feature_enabled?(:shortcuts)
|
28
|
+
tr8n_application.shortcuts.each do |key, script|
|
29
|
+
%>
|
30
|
+
shortcut.add('<%=key.html_safe%>', function() {
|
31
|
+
<%= script.html_safe %>
|
84
32
|
});
|
85
|
-
|
33
|
+
<%
|
34
|
+
end
|
35
|
+
end
|
36
|
+
%>
|
37
|
+
if (typeof(tr8n_on_ready) === 'function') {
|
38
|
+
tr8n_on_ready();
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
window.document.getElementsByTagName('head')[0].appendChild(script);
|
86
43
|
})();
|
87
44
|
</script>
|
88
|
-
|
89
|
-
|
90
45
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,34 @@
|
|
1
|
-
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
|
+
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
|
32
|
+
Rails.application.routes.draw do
|
33
|
+
get '/tr8n/upgrade' => 'tr8n_client_sdk/cache#upgrade'
|
2
34
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
|
+
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
|
32
|
+
require 'i18n/backend/base'
|
33
|
+
require 'tr8n_core'
|
34
|
+
|
35
|
+
module I18n
|
36
|
+
module Backend
|
37
|
+
class Tr8n < I18n::Backend::Simple
|
38
|
+
|
39
|
+
module Implementation
|
40
|
+
include Base, Flatten
|
41
|
+
|
42
|
+
def application
|
43
|
+
::Tr8n.session.application
|
44
|
+
end
|
45
|
+
|
46
|
+
def available_locales
|
47
|
+
application.locales
|
48
|
+
end
|
49
|
+
|
50
|
+
def lookup(locale, key, scope = [], options = {})
|
51
|
+
default_key = super(application.default_locale, key, scope, options)
|
52
|
+
default_key ||= key
|
53
|
+
application.language(locale.to_s).translate(default_key)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
include Implementation
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/tasks/tr8n.rake
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
|
+
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
|
32
|
+
require 'tr8n_core'
|
33
|
+
|
34
|
+
namespace :tr8n do
|
35
|
+
|
36
|
+
namespace :cache do
|
37
|
+
|
38
|
+
desc 'upgrades shared translation cache'
|
39
|
+
task :upgrade => :environment do
|
40
|
+
Tr8n.cache.upgrade_version
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'generates local file cache'
|
44
|
+
task :generate => :environment do
|
45
|
+
Tr8nCore::Generators::Cache::File.new.run
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'rolls back to the previous version'
|
49
|
+
task :rollback => :environment do
|
50
|
+
Tr8nCore::Generators::Cache::File.new.rollback
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'rolls up to the next version'
|
54
|
+
task :rollup => :environment do
|
55
|
+
Tr8nCore::Generators::Cache::File.new.rollup
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
#--
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
4
4
|
#
|
5
5
|
# _______ _ _ _ ______ _
|
6
6
|
# |__ __| | | | | (_) | ____| | |
|
@@ -30,12 +30,10 @@
|
|
30
30
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
31
|
#++
|
32
32
|
|
33
|
-
require 'dalli' if defined?(Dalli)
|
34
|
-
|
35
33
|
class Tr8n::CacheAdapters::Rails < Tr8n::Cache
|
36
34
|
|
37
35
|
def initialize
|
38
|
-
Tr8n.logger.info(
|
36
|
+
Tr8n.logger.info('Initializing Rails cache...')
|
39
37
|
@cache = Rails.cache
|
40
38
|
end
|
41
39
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
4
|
# _______ _ _ _ ______ _
|
5
5
|
# |__ __| | | | | (_) | ____| | |
|
@@ -34,11 +34,11 @@ module Tr8nClientSdk
|
|
34
34
|
############################################################
|
35
35
|
# There are three ways to call the tr method
|
36
36
|
#
|
37
|
-
# tr(label, desc =
|
37
|
+
# tr(label, desc = '', tokens = {}, options = {})
|
38
38
|
# or
|
39
39
|
# tr(label, tokens = {}, options = {})
|
40
40
|
# or
|
41
|
-
# tr(:label => label, :description =>
|
41
|
+
# tr(:label => label, :description => '', :tokens => {}, :options => {})
|
42
42
|
############################################################
|
43
43
|
def tr(label, description = '', tokens = {}, options = {})
|
44
44
|
params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
|
@@ -65,7 +65,7 @@ module Tr8nClientSdk
|
|
65
65
|
return text.tr8n_translated.html_safe
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
Tr8n.session.target_language.translate(params).tr8n_translated.html_safe
|
69
69
|
rescue Tr8n::Exception => ex
|
70
70
|
#pp ex, ex.backtrace
|
71
71
|
Tr8n.logger.error(ex.message)
|
@@ -74,24 +74,24 @@ module Tr8nClientSdk
|
|
74
74
|
end
|
75
75
|
|
76
76
|
# for translating labels
|
77
|
-
def trl(label, description =
|
77
|
+
def trl(label, description = '', tokens = {}, options = {})
|
78
78
|
params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
|
79
79
|
params[:options][:skip_decorations] = true
|
80
80
|
tr(params)
|
81
81
|
end
|
82
82
|
|
83
83
|
# flash notice
|
84
|
-
def trfn(label, desc =
|
84
|
+
def trfn(label, desc = '', tokens = {}, options = {})
|
85
85
|
flash[:trfn] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
|
86
86
|
end
|
87
87
|
|
88
88
|
# flash error
|
89
|
-
def trfe(label, desc =
|
89
|
+
def trfe(label, desc = '', tokens = {}, options = {})
|
90
90
|
flash[:trfe] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
|
91
91
|
end
|
92
92
|
|
93
93
|
# flash warning
|
94
|
-
def trfw(label, desc =
|
94
|
+
def trfw(label, desc = '', tokens = {}, options = {})
|
95
95
|
flash[:trfw] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
|
96
96
|
end
|
97
97
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
4
|
# _______ _ _ _ ______ _
|
5
5
|
# |__ __| | | | | (_) | ____| | |
|
@@ -73,36 +73,13 @@ module Tr8nClientSdk
|
|
73
73
|
nil
|
74
74
|
end
|
75
75
|
|
76
|
-
def tr8n_cookie_name
|
77
|
-
"tr8n_#{tr8n_application.key}"
|
78
|
-
end
|
79
|
-
|
80
|
-
def tr8n_cookie
|
81
|
-
request.cookies[tr8n_cookie_name]
|
82
|
-
end
|
83
|
-
|
84
|
-
def tr8n_cookie_params
|
85
|
-
@tr8n_cookie_params ||= begin
|
86
|
-
if tr8n_cookie
|
87
|
-
cookie_params = Tr8n::Utils.decode_and_verify_params(tr8n_cookie, tr8n_application.secret)
|
88
|
-
Tr8n.logger.info(cookie_params.inspect)
|
89
|
-
cookie_params
|
90
|
-
else
|
91
|
-
{}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
76
|
def tr8n_translator_locale
|
97
|
-
tr8n_cookie_params[
|
77
|
+
tr8n_cookie_params['locale']
|
98
78
|
end
|
99
79
|
|
100
|
-
def
|
80
|
+
def tr8n_locale
|
101
81
|
self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method
|
102
82
|
rescue
|
103
|
-
# fallback onto the cookie params from the service
|
104
|
-
return tr8n_translator_locale if tr8n_translator_locale
|
105
|
-
|
106
83
|
# fallback to the default session based locale implementation
|
107
84
|
# choose the first language from the accepted languages header
|
108
85
|
session[:locale] = tr8n_user_preferred_locale unless session[:locale]
|
@@ -110,33 +87,27 @@ module Tr8nClientSdk
|
|
110
87
|
session[:locale] || Tr8n.config.default_locale
|
111
88
|
end
|
112
89
|
|
113
|
-
def
|
90
|
+
def tr8n_user
|
114
91
|
self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method
|
115
92
|
rescue
|
116
93
|
nil
|
117
94
|
end
|
118
95
|
|
119
|
-
def tr8n_init_current_translator
|
120
|
-
if tr8n_cookie_params["translator"]
|
121
|
-
Tr8n::Translator.new(tr8n_cookie_params["translator"].merge(:application => tr8n_application))
|
122
|
-
else
|
123
|
-
nil
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
96
|
def tr8n_init_client_sdk
|
128
97
|
return if Tr8n.config.disabled?
|
129
98
|
|
130
99
|
@tr8n_started_at = Time.now
|
131
100
|
|
132
|
-
Tr8n.session.init
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
101
|
+
Tr8n.session.init(
|
102
|
+
:cookies => request.cookies,
|
103
|
+
:locale => tr8n_locale,
|
104
|
+
:user => tr8n_user,
|
105
|
+
:source => tr8n_source,
|
106
|
+
:component => tr8n_component
|
107
|
+
)
|
137
108
|
|
138
|
-
|
139
|
-
Tr8n.session.
|
109
|
+
I18n.enforce_available_locales = false
|
110
|
+
I18n.locale = Tr8n.session.current_language.locale
|
140
111
|
end
|
141
112
|
|
142
113
|
def tr8n_reset_client_sdk
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
4
|
# _______ _ _ _ ______ _
|
5
5
|
# |__ __| | | | | (_) | ____| | |
|
@@ -118,14 +118,13 @@ module Tr8nClientSdk
|
|
118
118
|
return ""
|
119
119
|
end
|
120
120
|
|
121
|
-
|
122
|
-
Thread.current[:block_options].push(opts)
|
121
|
+
Tr8n.session.push_block_options(opts)
|
123
122
|
|
124
123
|
if block_given?
|
125
124
|
ret = capture(&block)
|
126
125
|
end
|
127
126
|
|
128
|
-
|
127
|
+
Tr8n.session.pop_block_options
|
129
128
|
ret
|
130
129
|
end
|
131
130
|
alias_method :tr8n_block, :tr8n_with_options_tag
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
4
|
# _______ _ _ _ ______ _
|
5
5
|
# |__ __| | | | | (_) | ____| | |
|
@@ -30,5 +30,5 @@
|
|
30
30
|
#++
|
31
31
|
|
32
32
|
module Tr8nClientSdk
|
33
|
-
VERSION = '4.1
|
33
|
+
VERSION = '4.2.1'
|
34
34
|
end
|
data/lib/tr8n_client_sdk.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
4
|
# _______ _ _ _ ______ _
|
5
5
|
# |__ __| | | | | (_) | ____| | |
|
@@ -34,6 +34,7 @@ require "tr8n_client_sdk/core/string"
|
|
34
34
|
require "tr8n_client_sdk/railtie"
|
35
35
|
require "tr8n_client_sdk/engine"
|
36
36
|
require "tr8n/cache_adapters/rails"
|
37
|
+
require "i18n/backend/tr8n"
|
37
38
|
|
38
39
|
module Tr8nClientSdk
|
39
40
|
|
metadata
CHANGED
@@ -1,46 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_client_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tr8n_core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '4.
|
33
|
+
version: '4.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '4.
|
40
|
+
version: '4.2'
|
41
41
|
description: Client SDK for Tr8n translation engine.
|
42
42
|
email:
|
43
|
-
- michael@
|
43
|
+
- michael@translationexchange.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
@@ -48,12 +48,14 @@ files:
|
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
|
+
- app/controllers/tr8n_client_sdk/cache_controller.rb
|
51
52
|
- app/views/tr8n_client_sdk/tags/_language_selector.html.erb
|
52
53
|
- app/views/tr8n_client_sdk/tags/_language_strip.html.erb
|
53
54
|
- app/views/tr8n_client_sdk/tags/_powered_by_tr8n.html.erb
|
54
55
|
- app/views/tr8n_client_sdk/tags/_scripts.html.erb
|
55
56
|
- config/routes.rb
|
56
|
-
- lib/
|
57
|
+
- lib/i18n/backend/tr8n.rb
|
58
|
+
- lib/tasks/tr8n.rake
|
57
59
|
- lib/tr8n/cache_adapters/rails.rb
|
58
60
|
- lib/tr8n_client_sdk.rb
|
59
61
|
- lib/tr8n_client_sdk/core/string.rb
|