tr8n_client_sdk 4.2.1 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +110 -108
- data/app/controllers/tr8n_client_sdk/{cache_controller.rb → tools_controller.rb} +18 -1
- data/app/views/tr8n_client_sdk/tags/_language_selector.html.erb +46 -17
- data/app/views/tr8n_client_sdk/tags/_scripts.html.erb +34 -35
- data/config/routes.rb +3 -1
- data/lib/tasks/tr8n_client_sdk.rake +47 -0
- data/lib/tr8n_client_sdk/extensions/action_controller_extension.rb +32 -18
- data/lib/tr8n_client_sdk/extensions/action_view_extension.rb +2 -2
- data/lib/tr8n_client_sdk/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd5aa83a24c9660d520dcc59cd80d85ba26baf7e
|
4
|
+
data.tar.gz: ff1d3a4ffa0d04cdf3024e94840d5527084cdff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4512dbccb63ab1fce2317dbe286632092ad9da2706fee4ae09012039cb5fe362b104c845eea1cf6d4620bd4802cf442517322ad908e3829e85977e631e9cbe2
|
7
|
+
data.tar.gz: 72ee88658fc1f34c68333e12c9e2257f440c325e470a2eaaade6108f291f53a41b7a16eb4ade1f1154d2b6d2c728913f44452a8d520ba4a315272570e3d768a5
|
data/README.md
CHANGED
@@ -15,18 +15,18 @@ This Client SDK provides tools for translating Rails applications into any langu
|
|
15
15
|
Installation
|
16
16
|
===================================
|
17
17
|
|
18
|
-
To integrate Tr8n SDK into your own application,
|
18
|
+
To integrate Tr8n SDK into your own application, add the gem to your app:
|
19
19
|
|
20
20
|
Add the following gem to your Gemfile:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
|
23
|
+
gem 'tr8n_client_sdk'
|
24
24
|
```
|
25
25
|
|
26
26
|
Install the gems:
|
27
27
|
|
28
28
|
```sh
|
29
|
-
|
29
|
+
$ bundle install
|
30
30
|
```
|
31
31
|
|
32
32
|
|
@@ -38,106 +38,113 @@ Create a tr8n initializer file with the following configuration:
|
|
38
38
|
config/initializers/tr8n.rb
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
Tr8n.configure do |config|
|
42
|
+
config.application = {
|
43
|
+
:key => YOUR_APP_KEY,
|
44
|
+
:secret => YOUR_APP_SECRET
|
45
|
+
}
|
46
|
+
end
|
47
47
|
```
|
48
48
|
|
49
|
-
|
49
|
+
For best performance, you must enable caching for Tr8n. You can specify the cache in the initializer.
|
50
50
|
|
51
|
-
If you are already using Rails caching, you
|
51
|
+
If you are already using Rails caching, you probably already specify it in your production file, like the following:
|
52
52
|
|
53
53
|
config/environments/production.rb
|
54
54
|
|
55
55
|
```ruby
|
56
|
-
|
57
|
-
|
58
|
-
|
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'})
|
59
58
|
```
|
60
59
|
|
60
|
+
Then all you need to do is specify that you want to use the Rails cache adapter in your Tr8n initializer:
|
61
|
+
|
61
62
|
config/initializers/tr8n.rb
|
62
63
|
|
63
64
|
```ruby
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
Tr8n.configure do |config|
|
66
|
+
config.cache = {
|
67
|
+
:enabled => true,
|
68
|
+
:adapter => 'rails',
|
69
|
+
:version => 1
|
70
|
+
}
|
71
|
+
end
|
71
72
|
```
|
72
73
|
|
73
74
|
Alternatively, you can provide a separate memcache server specifically for translations:
|
74
75
|
|
75
76
|
```ruby
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
85
86
|
```
|
86
87
|
|
87
88
|
You can also use Redis to persist your translations cache:
|
88
89
|
|
89
90
|
```ruby
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
99
100
|
```
|
100
101
|
|
101
102
|
The above examples use shared caching model - all your Rails processes on all your servers share the same translation cache. This approach
|
102
103
|
will save you memory space, as well as allow you to invalidate/redeploy your translations cache without having to redeploy your application.
|
103
104
|
|
104
|
-
To update the cache,
|
105
|
+
To update the cache, execute the following line of code:
|
105
106
|
|
106
107
|
```ruby
|
107
|
-
|
108
|
+
Tr8n.cache.upgrade_version
|
108
109
|
```
|
109
110
|
|
110
|
-
Or you can run the rake command:
|
111
|
+
Or you can run the rake command from any of your app instances:
|
111
112
|
|
112
113
|
```sh
|
113
|
-
|
114
|
+
$ bundle exec rake tr8n:cache:upgrade
|
114
115
|
```
|
115
116
|
|
116
|
-
This will effectively invalidate your current cache and rebuilt it with the latest translations from Translation Exchange
|
117
|
+
This will effectively invalidate your current cache and rebuilt it with the latest translations from Translation Exchange CDN.
|
117
118
|
|
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,
|
119
120
|
but it will be faster at serving translations and this approach does not require cache warmup.
|
120
121
|
|
121
|
-
|
122
|
+
To specify in-memory, file-based cache, provide the following configuration:
|
122
123
|
|
123
124
|
```ruby
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
133
134
|
```
|
134
135
|
|
135
|
-
If you set ':segmented' to 'true'
|
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.
|
136
137
|
|
137
138
|
The file based cache must be generated before you deploy your application using the following command:
|
138
139
|
|
139
140
|
```sh
|
140
|
-
|
141
|
+
$ bundle exec rake tr8n:cache:generate
|
142
|
+
```
|
143
|
+
|
144
|
+
You can also rollback to the previous file cache using:
|
145
|
+
|
146
|
+
```sh
|
147
|
+
$ bundle exec rake tr8n:cache:rollback
|
141
148
|
```
|
142
149
|
|
143
150
|
|
@@ -147,15 +154,13 @@ Integration
|
|
147
154
|
In the HEAD section of your layout, add:
|
148
155
|
|
149
156
|
```ruby
|
150
|
-
|
157
|
+
<%= tr8n_scripts_tag %>
|
151
158
|
```
|
152
159
|
|
153
|
-
You are done, tr8n is now running in your app.
|
154
|
-
|
155
160
|
Now you can simply add the default language selector anywhere on your page using:
|
156
161
|
|
157
162
|
```ruby
|
158
|
-
|
163
|
+
<%= tr8n_language_selector_tag %>
|
159
164
|
```
|
160
165
|
|
161
166
|
The default language selector is used to enable/disable translation modes. It may be useful on staging or translation
|
@@ -165,19 +170,19 @@ To use a dropdown language selector that uses locale in the url parameter, use:
|
|
165
170
|
|
166
171
|
```ruby
|
167
172
|
<%= tr8n_language_selector_tag(
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
173
|
+
:type => :dropdown,
|
174
|
+
:style => "margin-top:15px",
|
175
|
+
:language => :english
|
176
|
+
) %>
|
172
177
|
```
|
173
178
|
|
174
179
|
Now you can use Tr8n's helper methods and TML (Translation Markup Language) to translate your strings:
|
175
180
|
|
176
181
|
```ruby
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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) %>
|
181
186
|
...
|
182
187
|
```
|
183
188
|
|
@@ -185,9 +190,7 @@ There are some additional methods that can be very useful. For instance, if you
|
|
185
190
|
you can simply use:
|
186
191
|
|
187
192
|
```ruby
|
188
|
-
|
189
|
-
"Hello World".translate
|
190
|
-
|
193
|
+
"Hello World".translate
|
191
194
|
```
|
192
195
|
|
193
196
|
Learn more about TML at: http://TranslationExchange.com/docs
|
@@ -202,7 +205,7 @@ you need to set the i18n backend to Tr8n. Add the following line to your tr8n in
|
|
202
205
|
config/initializers/tr8n.rb
|
203
206
|
|
204
207
|
```ruby
|
205
|
-
|
208
|
+
I18n.backend = I18n::Backend::Tr8n.new
|
206
209
|
```
|
207
210
|
|
208
211
|
Now the "t" function will automatically fallback onto "tr" function. If you have the following in your base language file:
|
@@ -210,25 +213,25 @@ Now the "t" function will automatically fallback onto "tr" function. If you have
|
|
210
213
|
config/locales/en.yml
|
211
214
|
|
212
215
|
```ruby
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
216
|
+
en:
|
217
|
+
hello: "Hello world"
|
218
|
+
my:
|
219
|
+
nested:
|
220
|
+
key: "This is a nested key"
|
218
221
|
```
|
219
222
|
|
220
223
|
Then you can call:
|
221
224
|
|
222
225
|
```ruby
|
223
|
-
|
224
|
-
|
226
|
+
<%= t(:hello) %>
|
227
|
+
<%= t("my.nested.key") %>
|
225
228
|
```
|
226
229
|
|
227
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:
|
228
231
|
|
229
232
|
```ruby
|
230
|
-
|
231
|
-
|
233
|
+
<%= tr("Hello World") %>
|
234
|
+
<%= tr("This is a nested key") %>
|
232
235
|
```
|
233
236
|
|
234
237
|
The above calls are equivalent.
|
@@ -240,29 +243,28 @@ Logging
|
|
240
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:
|
241
244
|
|
242
245
|
```ruby
|
243
|
-
|
246
|
+
Tr8n.configure do |config|
|
244
247
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
248
|
+
config.logger = {
|
249
|
+
:enabled => true,
|
250
|
+
:path => "#{Rails.root}/log/tr8n.log",
|
251
|
+
:level => 'debug'
|
252
|
+
}
|
250
253
|
|
251
|
-
|
254
|
+
end
|
252
255
|
```
|
253
256
|
|
254
|
-
|
255
257
|
Customization
|
256
258
|
===================================
|
257
259
|
|
258
260
|
Tr8n comes with default settings for the rules engine. For example, it assumes that you have the following methods in your ApplicationController:
|
259
261
|
|
260
262
|
```ruby
|
261
|
-
|
262
|
-
|
263
|
+
def current_user
|
264
|
+
end
|
263
265
|
|
264
|
-
|
265
|
-
|
266
|
+
def current_locale
|
267
|
+
end
|
266
268
|
```
|
267
269
|
|
268
270
|
Tr8n only needs the current_user method if your site needs to use gender based rules for the viewing user.
|
@@ -272,13 +274,13 @@ Similarly, if you prefer to use your own mechanism for storing and retrieving us
|
|
272
274
|
If you need to adjust those method names, you can set them in the config:
|
273
275
|
|
274
276
|
```ruby
|
275
|
-
|
277
|
+
Tr8n.configure do |config|
|
276
278
|
|
277
|
-
|
279
|
+
config.current_user_method = :my_user
|
278
280
|
|
279
|
-
|
281
|
+
config.current_locale_method = :my_locale
|
280
282
|
|
281
|
-
|
283
|
+
end
|
282
284
|
```
|
283
285
|
|
284
286
|
|
@@ -288,9 +290,9 @@ Tr8n Client SDK Sample
|
|
288
290
|
The best way to start using the SDK is to run a sample application that comes bundled with this SDK.
|
289
291
|
|
290
292
|
```sh
|
291
|
-
|
292
|
-
|
293
|
-
|
293
|
+
$ git clone https://github.com/tr8n/tr8n_rails_clientsdk.git
|
294
|
+
$ cd tr8n_rails_clientsdk/spec/dummy
|
295
|
+
$ bundle
|
294
296
|
```
|
295
297
|
|
296
298
|
Before you running the application, visit TranslationExchange.com, register as a new user and create a new application.
|
@@ -298,16 +300,16 @@ Before you running the application, visit TranslationExchange.com, register as a
|
|
298
300
|
Update your key and secret in the following file: config/initializers/tr8n.rb
|
299
301
|
|
300
302
|
```ruby
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
303
|
+
config.application = {
|
304
|
+
:key => YOUR_KEY,
|
305
|
+
:secret => YOUR_SECRET
|
306
|
+
}
|
305
307
|
```
|
306
308
|
|
307
309
|
Now you can start the application by running:
|
308
310
|
|
309
311
|
```sh
|
310
|
-
|
312
|
+
$ bundle exec rails s
|
311
313
|
```
|
312
314
|
|
313
315
|
|
@@ -319,9 +321,9 @@ http://localhost:3000
|
|
319
321
|
Links
|
320
322
|
==================
|
321
323
|
|
322
|
-
* Register on TranslationExchange.com:
|
324
|
+
* Register on TranslationExchange.com: http://translationexchange.com
|
323
325
|
|
324
|
-
* Read
|
326
|
+
* Read Translation Exchange documentation: http://translationexchange.com/docs
|
325
327
|
|
326
328
|
* Follow TranslationExchange on Twitter: https://twitter.com/translationx
|
327
329
|
|
@@ -333,7 +335,7 @@ Links
|
|
333
335
|
Copyright and license
|
334
336
|
==================
|
335
337
|
|
336
|
-
Copyright (c)
|
338
|
+
Copyright (c) 2015 Translation Exchange Inc, TranslationExchange.com
|
337
339
|
|
338
340
|
Permission is hereby granted, free of charge, to any person obtaining
|
339
341
|
a copy of this software and associated documentation files (the
|
@@ -30,9 +30,26 @@
|
|
30
30
|
#++
|
31
31
|
|
32
32
|
module Tr8nClientSdk
|
33
|
-
class
|
33
|
+
class ToolsController < ApplicationController
|
34
|
+
|
34
35
|
def upgrade
|
35
36
|
Tr8n.cache.upgrade_version
|
37
|
+
redirect_back
|
38
|
+
end
|
39
|
+
|
40
|
+
def enable
|
41
|
+
tr8n_toggle_tools(true)
|
42
|
+
redirect_back
|
43
|
+
end
|
44
|
+
|
45
|
+
def disable
|
46
|
+
tr8n_toggle_tools(false)
|
47
|
+
redirect_back
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def redirect_back
|
36
53
|
redirect_to(request.env['HTTP_REFERER'] || '/')
|
37
54
|
end
|
38
55
|
end
|
@@ -1,4 +1,45 @@
|
|
1
|
-
<% if
|
1
|
+
<% if tr8n_session.tools_enabled? or type.blank? %>
|
2
|
+
<%
|
3
|
+
if tr8n_session.tools_enabled?
|
4
|
+
opts[:method] = 'Tr8n.UI.LanguageSelector.show(); return false;'
|
5
|
+
end
|
6
|
+
%>
|
7
|
+
|
8
|
+
<%= link_to('#',
|
9
|
+
:onclick => (opts[:method] || "alert('Custom language selector can be specified by passing it in the method attribute of the language selector tag.');"),
|
10
|
+
:style => (opts[:style] || 'padding-right:5px;text-decoration:none'),
|
11
|
+
:class => opts[:class]
|
12
|
+
) do %>
|
13
|
+
<% unless opts[:hide_flag] %>
|
14
|
+
<%= image_tag(tr8n_current_language.flag_url, :style => "align:middle") %>
|
15
|
+
|
16
|
+
<% end %>
|
17
|
+
<% if opts[:language] == :native %>
|
18
|
+
<%= tr8n_current_language.native_name %>
|
19
|
+
<% elsif opts[:language] == :english %>
|
20
|
+
<%= tr8n_current_language.english_name %>
|
21
|
+
<% else %>
|
22
|
+
<%= tr8n_current_language.english_name %>
|
23
|
+
<% end %>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<% elsif type == :list %>
|
27
|
+
<div style="padding-top:10px;">
|
28
|
+
<% tr8n_application.languages.each_with_index do |lang, index| %>
|
29
|
+
<% next if opts[:limit] and index >= opts[:limit] %>
|
30
|
+
<%= link_to(params.merge(:locale => lang.locale), :style => (opts[:style] || 'padding-right:5px;text-decoration:none'), :class => opts[:class]) do %>
|
31
|
+
<% if opts[:flags_only] or opts[:flags] %>
|
32
|
+
<%= image_tag(lang.flag_url) %>
|
33
|
+
<% end %>
|
34
|
+
<% unless opts[:flags_only] %>
|
35
|
+
<%= lang.english_name %>
|
36
|
+
<% end %>
|
37
|
+
<% end %>
|
38
|
+
<% end %>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<% elsif type == :dropdown %>
|
42
|
+
|
2
43
|
<script>
|
3
44
|
function tr8n_change_locale(selector) {
|
4
45
|
var query_parts = window.location.href.split('?');
|
@@ -23,31 +64,19 @@
|
|
23
64
|
window.location = destination;
|
24
65
|
}
|
25
66
|
</script>
|
67
|
+
|
26
68
|
<select id="tr8n_language_selector" onchange="tr8n_change_locale(this)" style="<%=opts[:style]%>" class="<%=opts[:class]%>">
|
27
69
|
<% tr8n_application.languages.each do |lang| %>
|
28
70
|
<option dir='ltr' value="<%=lang.locale%>" <%="selected" if lang.locale == tr8n_current_locale %>>
|
29
71
|
<% if opts[:language] == :native %>
|
30
72
|
<%= lang.native_name %>
|
31
73
|
<% elsif opts[:language] == :english %>
|
32
|
-
|
74
|
+
<%= lang.english_name %>
|
33
75
|
<% else %>
|
34
76
|
<%= lang.english_name %>
|
35
77
|
<% end %>
|
36
78
|
</option>
|
37
79
|
<% end %>
|
38
80
|
</select>
|
39
|
-
|
40
|
-
|
41
|
-
<% unless opts[:hide_flag] %>
|
42
|
-
<%= image_tag(tr8n_current_language.flag_url, :style => "align:middle") %>
|
43
|
-
|
44
|
-
<% end %>
|
45
|
-
<% if opts[:language] == :native %>
|
46
|
-
<%= tr8n_current_language.native_name %>
|
47
|
-
<% elsif opts[:language] == :english %>
|
48
|
-
<%= tr8n_current_language.english_name %>
|
49
|
-
<% else %>
|
50
|
-
<%= tr8n_current_language.english_name %>
|
51
|
-
<% end %>
|
52
|
-
</a>
|
53
|
-
<% end %>
|
81
|
+
|
82
|
+
<% end %>
|
@@ -6,40 +6,39 @@
|
|
6
6
|
.tr8n_txtl {<%=tr8n_style_attribute_tag('text-align', 'left')%> !important;}
|
7
7
|
</style>
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
<% if tr8n_session.tools_enabled? %>
|
10
|
+
<script>
|
11
|
+
(function() {
|
12
|
+
if (window.tr8n_already_initialized) return;
|
13
|
+
window.tr8n_already_initialized = true;
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
};
|
41
|
-
|
42
|
-
|
43
|
-
})();
|
44
|
-
</script>
|
15
|
+
var script = window.document.createElement('script');
|
16
|
+
script.setAttribute('id', 'tr8n-tools');
|
17
|
+
script.setAttribute('type', 'application/javascript');
|
18
|
+
script.setAttribute('src', '<%= tr8n_application.tools['javascript'] %>');
|
19
|
+
script.setAttribute('charset', 'UTF-8');
|
20
|
+
script.onload = function() {
|
21
|
+
Tr8n.Utils.insertCSS(window.document, "<%= tr8n_application.tools['stylesheet'] %>", false);
|
22
|
+
Tr8n.Utils.insertCSS(window.document, "<%= tr8n_application.css %>", true);
|
23
|
+
Tr8n.app_key = '<%= tr8n_application.key %>';
|
24
|
+
Tr8n.host = '<%= tr8n_application.tools['host'] %>';
|
25
|
+
Tr8n.locale = '<%= tr8n_current_language.locale %>';
|
26
|
+
Tr8n.sources = [];
|
27
|
+
<%
|
28
|
+
if tr8n_application.feature_enabled?(:shortcuts)
|
29
|
+
tr8n_application.shortcuts.each do |key, script|
|
30
|
+
%>
|
31
|
+
shortcut.add('<%=key.html_safe%>', function() {<%= script.html_safe %>});
|
32
|
+
<%
|
33
|
+
end
|
34
|
+
end
|
35
|
+
%>
|
36
|
+
if (typeof(tr8n_on_ready) === 'function') {
|
37
|
+
tr8n_on_ready();
|
38
|
+
}
|
39
|
+
};
|
40
|
+
window.document.getElementsByTagName('head')[0].appendChild(script);
|
41
|
+
})();
|
42
|
+
</script>
|
43
|
+
<% end %>
|
45
44
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -30,5 +30,7 @@
|
|
30
30
|
#++
|
31
31
|
|
32
32
|
Rails.application.routes.draw do
|
33
|
-
get '/tr8n/upgrade' => 'tr8n_client_sdk/
|
33
|
+
get '/tr8n/upgrade' => 'tr8n_client_sdk/tools#upgrade'
|
34
|
+
get '/tr8n/on' => 'tr8n_client_sdk/tools#enable'
|
35
|
+
get '/tr8n/off' => 'tr8n_client_sdk/tools#disable'
|
34
36
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2014 Michael Berkovich, 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
|
+
namespace :tr8n_client_sdk do
|
33
|
+
|
34
|
+
task :init => :environment do
|
35
|
+
|
36
|
+
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
|
+
end
|
@@ -71,40 +71,54 @@ module Tr8nClientSdk
|
|
71
71
|
# Overwrite this method in a controller to assign a custom component for all views
|
72
72
|
def tr8n_component
|
73
73
|
nil
|
74
|
-
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def tr8n_toggle_tools(flag)
|
77
|
+
session[:tr8n_tools_disabled] = !flag
|
78
|
+
end
|
75
79
|
|
76
|
-
def
|
77
|
-
|
80
|
+
def tr8n_tools_enabled?
|
81
|
+
not session[:tr8n_tools_disabled]
|
78
82
|
end
|
79
83
|
|
80
84
|
def tr8n_locale
|
81
85
|
self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method
|
82
86
|
rescue
|
83
|
-
# fallback to the default session based locale implementation
|
84
|
-
# choose the first language from the accepted languages header
|
85
87
|
session[:locale] = tr8n_user_preferred_locale unless session[:locale]
|
86
88
|
session[:locale] = params[:locale] if params[:locale]
|
87
89
|
session[:locale] || Tr8n.config.default_locale
|
88
90
|
end
|
89
91
|
|
90
|
-
def tr8n_user
|
91
|
-
self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method
|
92
|
-
rescue
|
93
|
-
nil
|
94
|
-
end
|
95
|
-
|
96
92
|
def tr8n_init_client_sdk
|
97
93
|
return if Tr8n.config.disabled?
|
98
94
|
|
99
95
|
@tr8n_started_at = Time.now
|
100
96
|
|
101
|
-
|
102
|
-
:
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
:
|
107
|
-
|
97
|
+
if params[:tr8n]
|
98
|
+
tr8n_toggle_tools(params[:tr8n] == 'on')
|
99
|
+
end
|
100
|
+
|
101
|
+
tr8n_session_params = {
|
102
|
+
:tools_enabled => tr8n_tools_enabled?,
|
103
|
+
:source => tr8n_source,
|
104
|
+
:component => tr8n_component
|
105
|
+
}
|
106
|
+
|
107
|
+
if Tr8n.config.current_user_method
|
108
|
+
begin
|
109
|
+
tr8n_session_params.merge!(:user => self.send(Tr8n.config.current_user_method))
|
110
|
+
rescue
|
111
|
+
# Tr8n.logger.error('Current user method is specified but not provided')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
if tr8n_tools_enabled? # gets translator and locale from the cookie
|
116
|
+
tr8n_session_params.merge!(:cookies => request.cookies)
|
117
|
+
else # uses default locale
|
118
|
+
tr8n_session_params.merge!(:locale => tr8n_locale)
|
119
|
+
end
|
120
|
+
|
121
|
+
Tr8n.session.init(tr8n_session_params)
|
108
122
|
|
109
123
|
I18n.enforce_available_locales = false
|
110
124
|
I18n.locale = Tr8n.session.current_language.locale
|
@@ -83,9 +83,9 @@ module Tr8nClientSdk
|
|
83
83
|
html.html_safe
|
84
84
|
end
|
85
85
|
|
86
|
-
def tr8n_language_selector_tag(opts = {})
|
86
|
+
def tr8n_language_selector_tag(type = nil, opts = {})
|
87
87
|
return unless Tr8n.config.enabled?
|
88
|
-
render(:partial => '/tr8n_client_sdk/tags/language_selector', :locals => {:opts => opts})
|
88
|
+
render(:partial => '/tr8n_client_sdk/tags/language_selector', :locals => {:type => type, :opts => opts})
|
89
89
|
end
|
90
90
|
|
91
91
|
def tr8n_language_strip_tag(opts = {})
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_client_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.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: 2015-01-
|
11
|
+
date: 2015-01-14 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: '4'
|
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: '4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tr8n_core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,7 +48,7 @@ files:
|
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
|
-
- app/controllers/tr8n_client_sdk/
|
51
|
+
- app/controllers/tr8n_client_sdk/tools_controller.rb
|
52
52
|
- app/views/tr8n_client_sdk/tags/_language_selector.html.erb
|
53
53
|
- app/views/tr8n_client_sdk/tags/_language_strip.html.erb
|
54
54
|
- app/views/tr8n_client_sdk/tags/_powered_by_tr8n.html.erb
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- config/routes.rb
|
57
57
|
- lib/i18n/backend/tr8n.rb
|
58
58
|
- lib/tasks/tr8n.rake
|
59
|
+
- lib/tasks/tr8n_client_sdk.rake
|
59
60
|
- lib/tr8n/cache_adapters/rails.rb
|
60
61
|
- lib/tr8n_client_sdk.rb
|
61
62
|
- lib/tr8n_client_sdk/core/string.rb
|