tr8n_client_sdk 3.2.5 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +207 -96
- 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/_language_strip.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/engine.rb +1 -1
- data/lib/tr8n_client_sdk/extensions/action_common_methods.rb +10 -10
- data/lib/tr8n_client_sdk/extensions/action_controller_extension.rb +13 -18
- data/lib/tr8n_client_sdk/extensions/action_view_extension.rb +9 -10
- data/lib/tr8n_client_sdk/railtie.rb +1 -1
- data/lib/tr8n_client_sdk/version.rb +10 -2
- data/lib/tr8n_client_sdk.rb +10 -1
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3770494b194f83875e4a23240ba9628436714de3
|
4
|
+
data.tar.gz: 95ece0319b440581d638894346c53780336c7d2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32d8d595c5c5f3e15bc273dc359d73a2436d7a00f28961d20fc12b570cecfab63b59f0eca04af15608832a59a7e97e0321a54d542e09e7409b7be065a87049a6
|
7
|
+
data.tar.gz: 51d8b36bf70dfa6074fa8a9e4cf67f1ed134fb5eef5493520f3ea039185b58c6350d3ec58bec99d5c597eb5a5baf356e5d78dc2c80fe167a8fccf9617d157914
|
data/{MIT-LICENSE → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -2,159 +2,239 @@
|
|
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
|
-
[![Build Status](https://travis-ci.org/tr8n/tr8n_rails_clientsdk.png?branch=
|
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
|
-
|
18
|
+
To integrate Tr8n SDK into your own application, add the gem to your app:
|
19
|
+
|
20
|
+
Add the following gem to your Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'tr8n_client_sdk', '~> 3.3'
|
24
|
+
```
|
25
|
+
|
26
|
+
Install the gems:
|
20
27
|
|
21
28
|
```sh
|
22
|
-
|
23
|
-
$ cd tr8n_rails_clientsdk/spec/dummy
|
24
|
-
$ bundle
|
29
|
+
$ bundle install
|
25
30
|
```
|
26
31
|
|
27
|
-
Before you running the application, visit TranslationExchange.com, register as a new user and create a new application.
|
28
32
|
|
29
|
-
|
33
|
+
Configuration
|
34
|
+
===================================
|
35
|
+
|
36
|
+
Create a tr8n initializer file with the following configuration:
|
37
|
+
|
38
|
+
config/initializers/tr8n.rb
|
30
39
|
|
31
40
|
```ruby
|
41
|
+
Tr8n.configure do |config|
|
32
42
|
config.application = {
|
33
|
-
:key =>
|
34
|
-
:secret =>
|
43
|
+
:key => YOUR_APP_KEY,
|
44
|
+
:secret => YOUR_APP_SECRET
|
35
45
|
}
|
46
|
+
end
|
36
47
|
```
|
37
48
|
|
38
|
-
|
49
|
+
For best performance, you must enable caching for Tr8n. You can specify the cache in the initializer.
|
39
50
|
|
40
|
-
|
41
|
-
|
51
|
+
If you are already using Rails caching, you probably already specify it in your production file, like the following:
|
52
|
+
|
53
|
+
config/environments/production.rb
|
54
|
+
|
55
|
+
```ruby
|
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'})
|
42
58
|
```
|
43
59
|
|
60
|
+
Then all you need to do is specify that you want to use the Rails cache adapter in your Tr8n initializer:
|
44
61
|
|
45
|
-
|
62
|
+
config/initializers/tr8n.rb
|
46
63
|
|
47
|
-
|
64
|
+
```ruby
|
65
|
+
Tr8n.configure do |config|
|
66
|
+
config.cache = {
|
67
|
+
:enabled => true,
|
68
|
+
:adapter => 'rails',
|
69
|
+
:version => 1
|
70
|
+
}
|
71
|
+
end
|
72
|
+
```
|
48
73
|
|
74
|
+
Alternatively, you can provide a separate memcache server specifically for translations:
|
49
75
|
|
76
|
+
```ruby
|
77
|
+
Tr8n.configure do |config|
|
78
|
+
config.cache = {
|
79
|
+
:enabled => true,
|
80
|
+
:adapter => 'memcache',
|
81
|
+
:host => 'localhost:11211',
|
82
|
+
:version => 1,
|
83
|
+
:timeout => 3600
|
84
|
+
}
|
85
|
+
end
|
86
|
+
```
|
50
87
|
|
88
|
+
You can also use Redis to persist your translations cache:
|
51
89
|
|
52
|
-
|
53
|
-
|
90
|
+
```ruby
|
91
|
+
Tr8n.configure do |config|
|
92
|
+
config.cache = {
|
93
|
+
:enabled => true,
|
94
|
+
:adapter => 'redis',
|
95
|
+
:host => 'localhost:6379',
|
96
|
+
:version => 1,
|
97
|
+
:timeout => 3600
|
98
|
+
}
|
99
|
+
end
|
100
|
+
```
|
54
101
|
|
55
|
-
|
102
|
+
The above examples use shared caching model - all your Rails processes on all your servers share the same translation cache. This approach
|
103
|
+
will save you memory space, as well as allow you to invalidate/redeploy your translations cache without having to redeploy your application.
|
56
104
|
|
57
|
-
|
105
|
+
To update the cache, execute the following line of code:
|
58
106
|
|
59
107
|
```ruby
|
60
|
-
|
108
|
+
Tr8n.cache.upgrade_version
|
61
109
|
```
|
62
110
|
|
63
|
-
|
111
|
+
Or you can run the rake command from any of your app instances:
|
64
112
|
|
65
113
|
```sh
|
66
|
-
|
114
|
+
$ bundle exec rake tr8n:cache:upgrade
|
67
115
|
```
|
68
116
|
|
69
|
-
|
117
|
+
This will effectively invalidate your current cache and rebuilt it with the latest translations from Translation Exchange CDN.
|
118
|
+
|
119
|
+
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,
|
120
|
+
but it will be faster at serving translations and this approach does not require cache warmup.
|
121
|
+
|
122
|
+
To specify in-memory, file-based cache, provide the following configuration:
|
70
123
|
|
71
124
|
```ruby
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
125
|
+
Tr8n.configure do |config|
|
126
|
+
config.cache = {
|
127
|
+
:enabled => true,
|
128
|
+
:adapter => 'file',
|
129
|
+
:path => 'config/tr8n',
|
130
|
+
:version => 'current',
|
131
|
+
:segmented => false
|
132
|
+
}
|
133
|
+
end
|
78
134
|
```
|
79
135
|
|
80
|
-
|
136
|
+
If you set ':segmented' to 'true', the cache will be generated for each source in your application. Otherwise, a single cache file will be generated per language for the entire application.
|
81
137
|
|
82
|
-
|
138
|
+
The file based cache must be generated before you deploy your application using the following command:
|
83
139
|
|
84
|
-
```
|
85
|
-
|
86
|
-
config.cache = {
|
87
|
-
:enabled => true,
|
88
|
-
:adapter => 'memcache',
|
89
|
-
:host => 'localhost:11211',
|
90
|
-
:version => 1,
|
91
|
-
:timeout => 3600
|
92
|
-
}
|
93
|
-
end
|
140
|
+
```sh
|
141
|
+
$ bundle exec rake tr8n:cache:generate
|
94
142
|
```
|
95
143
|
|
96
|
-
|
144
|
+
You can also rollback to the previous file cache using:
|
97
145
|
|
98
|
-
```
|
99
|
-
|
100
|
-
config.cache = {
|
101
|
-
:enabled => true,
|
102
|
-
:adapter => 'redis',
|
103
|
-
:host => 'localhost:6379',
|
104
|
-
:version => 1,
|
105
|
-
:timeout => 3600
|
106
|
-
}
|
107
|
-
end
|
146
|
+
```sh
|
147
|
+
$ bundle exec rake tr8n:cache:rollback
|
108
148
|
```
|
109
149
|
|
110
|
-
To see a full list of supported cache adapters or to create your own cache adapter, visit TranslationExchange.com/docs
|
111
150
|
|
151
|
+
Integration
|
152
|
+
===================================
|
112
153
|
|
113
154
|
In the HEAD section of your layout, add:
|
114
155
|
|
115
156
|
```ruby
|
116
|
-
|
157
|
+
<%= tr8n_scripts_tag %>
|
117
158
|
```
|
118
159
|
|
119
|
-
You are done, tr8n is now running in your app.
|
120
|
-
|
121
160
|
Now you can simply add the default language selector anywhere on your page using:
|
122
161
|
|
123
162
|
```ruby
|
124
|
-
|
163
|
+
<%= tr8n_language_selector_tag %>
|
164
|
+
```
|
165
|
+
|
166
|
+
The default language selector is used to enable/disable translation modes. It may be useful on staging or translation
|
167
|
+
server, but it may not be ideal on production. There are a number of alternative language selectors you can use, including your own.
|
168
|
+
|
169
|
+
To use a dropdown language selector that uses locale in the url parameter, use:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
<%= tr8n_language_selector_tag(
|
173
|
+
:type => :dropdown,
|
174
|
+
:style => "margin-top:15px",
|
175
|
+
:language => :english
|
176
|
+
) %>
|
125
177
|
```
|
126
178
|
|
127
|
-
|
179
|
+
Now you can use Tr8n's helper methods and TML (Translation Markup Language) to translate your strings:
|
128
180
|
|
129
|
-
```
|
130
|
-
|
131
|
-
|
132
|
-
|
181
|
+
```ruby
|
182
|
+
<%= tr("Hello World") %>
|
183
|
+
<%= tr("You have {count || message}", count: 5) %>
|
184
|
+
<%= tr("{actor} sent {target} [bold: {count || gift}]", actor: actor_user, target: target_user, count: 5) %>
|
185
|
+
<%= tr("{actor} uploaded [bold: {count || photo}] to {actor | his, her} photo album.", actor: current_user, count: 5) %>
|
133
186
|
...
|
134
187
|
```
|
135
188
|
|
136
|
-
|
189
|
+
There are some additional methods that can be very useful. For instance, if you want to translate something inside a model,
|
190
|
+
you can simply use:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
"Hello World".translate
|
194
|
+
```
|
195
|
+
|
196
|
+
Learn more about TML at: http://TranslationExchange.com/docs
|
137
197
|
|
138
198
|
|
139
|
-
|
199
|
+
I18n fallback
|
140
200
|
===================================
|
141
201
|
|
142
|
-
|
202
|
+
If your application is already using the standard i18n framework, you can mix in the Tr8n framework on top of it. To do so,
|
203
|
+
you need to set the i18n backend to Tr8n. Add the following line to your tr8n initializer:
|
204
|
+
|
205
|
+
config/initializers/tr8n.rb
|
143
206
|
|
144
207
|
```ruby
|
145
|
-
|
208
|
+
I18n.backend = I18n::Backend::Tr8n.new
|
146
209
|
```
|
147
210
|
|
148
|
-
|
211
|
+
Now the "t" function will automatically fallback onto "tr" function. If you have the following in your base language file:
|
212
|
+
|
213
|
+
config/locales/en.yml
|
149
214
|
|
215
|
+
```ruby
|
216
|
+
en:
|
217
|
+
hello: "Hello world"
|
218
|
+
my:
|
219
|
+
nested:
|
220
|
+
key: "This is a nested key"
|
221
|
+
```
|
150
222
|
|
151
|
-
|
223
|
+
Then you can call:
|
152
224
|
|
153
|
-
```
|
154
|
-
|
225
|
+
```ruby
|
226
|
+
<%= t(:hello) %>
|
227
|
+
<%= t("my.nested.key") %>
|
228
|
+
```
|
229
|
+
|
230
|
+
And the i18n will use Translation Exchange as the backend for your translations. On top of it, you can continue using Tr8n's extensions:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
<%= tr("Hello World") %>
|
234
|
+
<%= tr("This is a nested key") %>
|
155
235
|
```
|
156
236
|
|
157
|
-
|
237
|
+
The above calls are equivalent.
|
158
238
|
|
159
239
|
|
160
240
|
Logging
|
@@ -163,29 +243,28 @@ Logging
|
|
163
243
|
Tr8n comes with its own logger. If you would like to see what the SDK is doing behind the scene, enable the logger and provide the file path for the log file:
|
164
244
|
|
165
245
|
```ruby
|
166
|
-
|
246
|
+
Tr8n.configure do |config|
|
167
247
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
248
|
+
config.logger = {
|
249
|
+
:enabled => true,
|
250
|
+
:path => "#{Rails.root}/log/tr8n.log",
|
251
|
+
:level => 'debug'
|
252
|
+
}
|
173
253
|
|
174
|
-
|
254
|
+
end
|
175
255
|
```
|
176
256
|
|
177
|
-
|
178
257
|
Customization
|
179
258
|
===================================
|
180
259
|
|
181
260
|
Tr8n comes with default settings for the rules engine. For example, it assumes that you have the following methods in your ApplicationController:
|
182
261
|
|
183
262
|
```ruby
|
184
|
-
|
185
|
-
|
263
|
+
def current_user
|
264
|
+
end
|
186
265
|
|
187
|
-
|
188
|
-
|
266
|
+
def current_locale
|
267
|
+
end
|
189
268
|
```
|
190
269
|
|
191
270
|
Tr8n only needs the current_user method if your site needs to use gender based rules for the viewing user.
|
@@ -195,36 +274,68 @@ Similarly, if you prefer to use your own mechanism for storing and retrieving us
|
|
195
274
|
If you need to adjust those method names, you can set them in the config:
|
196
275
|
|
197
276
|
```ruby
|
198
|
-
|
277
|
+
Tr8n.configure do |config|
|
278
|
+
|
279
|
+
config.current_user_method = :my_user
|
280
|
+
|
281
|
+
config.current_locale_method = :my_locale
|
282
|
+
|
283
|
+
end
|
284
|
+
```
|
199
285
|
|
200
|
-
config.current_user_method = :my_user
|
201
286
|
|
202
|
-
|
287
|
+
Tr8n Client SDK Sample
|
288
|
+
===================================
|
289
|
+
|
290
|
+
The best way to start using the SDK is to run a sample application that comes bundled with this SDK.
|
203
291
|
|
204
|
-
|
292
|
+
```sh
|
293
|
+
$ git clone https://github.com/tr8n/tr8n_rails_clientsdk.git
|
294
|
+
$ cd tr8n_rails_clientsdk/spec/dummy
|
295
|
+
$ bundle
|
205
296
|
```
|
206
297
|
|
298
|
+
Before you running the application, visit TranslationExchange.com, register as a new user and create a new application.
|
299
|
+
|
300
|
+
Update your key and secret in the following file: config/initializers/tr8n.rb
|
301
|
+
|
302
|
+
```ruby
|
303
|
+
config.application = {
|
304
|
+
:key => YOUR_KEY,
|
305
|
+
:secret => YOUR_SECRET
|
306
|
+
}
|
307
|
+
```
|
308
|
+
|
309
|
+
Now you can start the application by running:
|
310
|
+
|
311
|
+
```sh
|
312
|
+
$ bundle exec rails s
|
313
|
+
```
|
314
|
+
|
315
|
+
|
316
|
+
This will start the dummy application on port 3000. Open your browser and point to:
|
317
|
+
|
318
|
+
http://localhost:3000
|
319
|
+
|
207
320
|
|
208
321
|
Links
|
209
322
|
==================
|
210
323
|
|
211
|
-
* Register on TranslationExchange.com:
|
212
|
-
|
213
|
-
* Read TranslationExchange's documentation: http://wiki.translationexchange.com
|
324
|
+
* Register on TranslationExchange.com: http://translationexchange.com
|
214
325
|
|
215
|
-
*
|
326
|
+
* Read Translation Exchange documentation: http://translationexchange.com/docs
|
216
327
|
|
217
328
|
* Follow TranslationExchange on Twitter: https://twitter.com/translationx
|
218
329
|
|
219
330
|
* Connect with TranslationExchange on Facebook: https://www.facebook.com/translationexchange
|
220
331
|
|
221
|
-
* If you have any questions or suggestions, contact us:
|
332
|
+
* If you have any questions or suggestions, contact us: feedback@translationexchange.com
|
222
333
|
|
223
334
|
|
224
335
|
Copyright and license
|
225
336
|
==================
|
226
337
|
|
227
|
-
Copyright (c)
|
338
|
+
Copyright (c) 2015 Translation Exchange Inc, TranslationExchange.com
|
228
339
|
|
229
340
|
Permission is hereby granted, free of charge, to any person obtaining
|
230
341
|
a copy of this software and associated documentation files (the
|
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
|
-
|
36
|
-
|
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
|
32
|
+
module Tr8nClientSdk
|
33
|
+
class CacheController < ApplicationController
|
34
|
+
def upgrade
|
35
|
+
Tr8n.cache.upgrade_version
|
36
|
+
redirect_to(request.env['HTTP_REFERER'] || '/')
|
37
|
+
end
|
45
38
|
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 %>
|
@@ -13,8 +13,8 @@
|
|
13
13
|
<% end %>
|
14
14
|
|
15
15
|
<% if featured_languages.size > 0 %>
|
16
|
-
|
17
|
-
<% end %>
|
16
|
+
<%=link_to_function("»".html_safe, "Tr8n.UI.LanguageSelector.show()") %>
|
17
|
+
<% end %>
|
18
18
|
</div>
|
19
19
|
<% end %>
|
20
20
|
<% 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
|
-
.tr8n_fltr {
|
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,16 +34,16 @@ 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
|
-
return label.html_safe if label.is_a?(String) and label.tr8n_translated?
|
45
|
-
|
46
44
|
params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
|
45
|
+
return params[:label].html_safe if params[:label].tr8n_translated?
|
46
|
+
|
47
47
|
params[:options][:caller] = caller
|
48
48
|
|
49
49
|
if request
|
@@ -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
|
# |__ __| | | | | (_) | ____| | |
|
@@ -97,7 +97,8 @@ module Tr8nClientSdk
|
|
97
97
|
tr8n_cookie_params["locale"]
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
|
101
|
+
def tr8n_locale
|
101
102
|
self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method
|
102
103
|
rescue
|
103
104
|
# fallback onto the cookie params from the service
|
@@ -110,33 +111,27 @@ module Tr8nClientSdk
|
|
110
111
|
session[:locale] || Tr8n.config.default_locale
|
111
112
|
end
|
112
113
|
|
113
|
-
def
|
114
|
+
def tr8n_user
|
114
115
|
self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method
|
115
116
|
rescue
|
116
117
|
nil
|
117
118
|
end
|
118
119
|
|
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
120
|
def tr8n_init_client_sdk
|
128
121
|
return if Tr8n.config.disabled?
|
129
122
|
|
130
123
|
@tr8n_started_at = Time.now
|
131
124
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
125
|
+
Tr8n.session.init(
|
126
|
+
:cookies => request.cookies,
|
127
|
+
:locale => tr8n_locale,
|
128
|
+
:user => tr8n_user,
|
129
|
+
:source => tr8n_source,
|
130
|
+
:component => tr8n_component
|
131
|
+
)
|
137
132
|
|
138
|
-
|
139
|
-
Tr8n.session.
|
133
|
+
I18n.enforce_available_locales = false
|
134
|
+
I18n.locale = Tr8n.session.current_language.locale
|
140
135
|
end
|
141
136
|
|
142
137
|
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
|
# |__ __| | | | | (_) | ____| | |
|
@@ -72,11 +72,11 @@ module Tr8nClientSdk
|
|
72
72
|
html << "<span dir='ltr'>"
|
73
73
|
|
74
74
|
name = case name_type
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
when :native then lang.native_name
|
76
|
+
when :english then lang.english_name
|
77
|
+
when :locale then lang.locale
|
78
|
+
else lang.full_name
|
79
|
+
end
|
80
80
|
|
81
81
|
html << name
|
82
82
|
html << "</span></span>"
|
@@ -108,7 +108,7 @@ module Tr8nClientSdk
|
|
108
108
|
def tr8n_select_month(date, options = {}, html_options = {})
|
109
109
|
month_names = options[:use_short_month] ? Tr8n.config.default_abbr_month_names : Tr8n.config.default_month_names
|
110
110
|
select_month(date, options.merge(
|
111
|
-
|
111
|
+
:use_month_names => month_names.collect{|month_name| tr8n_current_language.translate(month_name, options[:description] || "Month name")}
|
112
112
|
), html_options)
|
113
113
|
end
|
114
114
|
|
@@ -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,6 +1,14 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
4
12
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
13
|
# a copy of this software and associated documentation files (the
|
6
14
|
# "Software"), to deal in the Software without restriction, including
|
@@ -22,5 +30,5 @@
|
|
22
30
|
#++
|
23
31
|
|
24
32
|
module Tr8nClientSdk
|
25
|
-
VERSION = '3.
|
33
|
+
VERSION = '3.3.1'
|
26
34
|
end
|
data/lib/tr8n_client_sdk.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2015 Translation Exchange Inc. http://translationexchange.com
|
3
3
|
#
|
4
|
+
# _______ _ _ _ ______ _
|
5
|
+
# |__ __| | | | | (_) | ____| | |
|
6
|
+
# | |_ __ __ _ _ __ ___| | __ _| |_ _ ___ _ __ | |__ __ _____| |__ __ _ _ __ __ _ ___
|
7
|
+
# | | '__/ _` | '_ \/ __| |/ _` | __| |/ _ \| '_ \| __| \ \/ / __| '_ \ / _` | '_ \ / _` |/ _ \
|
8
|
+
# | | | | (_| | | | \__ \ | (_| | |_| | (_) | | | | |____ > < (__| | | | (_| | | | | (_| | __/
|
9
|
+
# |_|_| \__,_|_| |_|___/_|\__,_|\__|_|\___/|_| |_|______/_/\_\___|_| |_|\__,_|_| |_|\__, |\___|
|
10
|
+
# __/ |
|
11
|
+
# |___/
|
4
12
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
13
|
# a copy of this software and associated documentation files (the
|
6
14
|
# "Software"), to deal in the Software without restriction, including
|
@@ -26,6 +34,7 @@ require "tr8n_client_sdk/core/string"
|
|
26
34
|
require "tr8n_client_sdk/railtie"
|
27
35
|
require "tr8n_client_sdk/engine"
|
28
36
|
require "tr8n/cache_adapters/rails"
|
37
|
+
require "i18n/backend/tr8n"
|
29
38
|
|
30
39
|
module Tr8nClientSdk
|
31
40
|
|
metadata
CHANGED
@@ -1,59 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_client_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.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-07 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.
|
41
|
-
description: Client SDK for
|
40
|
+
version: '4.2'
|
41
|
+
description: Client SDK for Tr8n translation engine.
|
42
42
|
email:
|
43
43
|
- michael@translationexchange.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
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
|
@@ -63,7 +65,7 @@ files:
|
|
63
65
|
- lib/tr8n_client_sdk/extensions/action_view_extension.rb
|
64
66
|
- lib/tr8n_client_sdk/railtie.rb
|
65
67
|
- lib/tr8n_client_sdk/version.rb
|
66
|
-
homepage: https://
|
68
|
+
homepage: https://github.com/tr8n/tr8n_rails_clientsdk
|
67
69
|
licenses:
|
68
70
|
- MIT-LICENSE
|
69
71
|
metadata: {}
|