tr8n 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -27
- data/Gemfile.lock +4 -4
- data/README.rdoc +24 -8
- data/VERSION +1 -1
- data/app/controllers/tr8n/home_controller.rb +0 -12
- data/app/helpers/application_helper.rb +0 -1
- data/app/models/tr8n/language.rb +4 -0
- data/app/models/tr8n/translation.rb +1 -1
- data/app/models/tr8n/translation_key.rb +7 -7
- data/app/views/tr8n/admin/clientsdk/index.html.erb +13 -13
- data/app/views/tr8n/admin/clientsdk/lb_samples.html.erb +1 -0
- data/app/views/tr8n/common/_scripts.html.erb +0 -8
- data/app/views/tr8n/language/select.html.erb +1 -1
- data/app/views/tr8n/phrases/_new_comment.html.erb +1 -1
- data/config/tr8n/config.yml +29 -29
- data/config/tr8n/tokens/data.yml +1 -1
- data/config/tr8n/tokens/decorations.yml +4 -4
- data/lib/application_helper.rb +53 -1
- data/lib/tr8n/controller_methods.rb +45 -7
- data/lib/tr8n/tokens/decoration_token.rb +23 -17
- data/public/tr8n/javascripts/tr8n_client_sdk.js +203 -69
- metadata +18 -10
- data/app/views/tr8n/home/docs.html.erb +0 -3
- data/app/views/tr8n/home/integration.html.erb +0 -564
- data/app/views/tr8n/home/rules.html.erb +0 -668
- data/app/views/tr8n/home/tokens.html.erb +0 -324
- data/lib/tr8n/common_methods.rb +0 -61
- data/lib/tr8n/helper_methods.rb +0 -304
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 3
|
10
|
+
version: 3.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Berkovich
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-19 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
version: 3.0.0
|
68
68
|
name: will_filter
|
69
69
|
version_requirements: *id003
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
prerelease: false
|
72
|
+
type: :runtime
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
name: sqlite3
|
83
|
+
version_requirements: *id004
|
70
84
|
description: Crowd-sourced translation engine for Rails.
|
71
85
|
email: theiceberk@gmail.com
|
72
86
|
executables: []
|
@@ -313,13 +327,9 @@ files:
|
|
313
327
|
- app/views/tr8n/help/your_languages.html.erb
|
314
328
|
- app/views/tr8n/help/your_translations.html.erb
|
315
329
|
- app/views/tr8n/home/credits.html.erb
|
316
|
-
- app/views/tr8n/home/docs.html.erb
|
317
330
|
- app/views/tr8n/home/index.html.erb
|
318
|
-
- app/views/tr8n/home/integration.html.erb
|
319
331
|
- app/views/tr8n/home/languages.html.erb
|
320
332
|
- app/views/tr8n/home/license.html.erb
|
321
|
-
- app/views/tr8n/home/rules.html.erb
|
322
|
-
- app/views/tr8n/home/tokens.html.erb
|
323
333
|
- app/views/tr8n/language/_basic_info.html.erb
|
324
334
|
- app/views/tr8n/language/_edit_language_case_rules.html.erb
|
325
335
|
- app/views/tr8n/language/_edit_language_cases.html.erb
|
@@ -428,14 +438,12 @@ files:
|
|
428
438
|
- lib/tr8n.rb
|
429
439
|
- lib/tr8n/active_dumper.rb
|
430
440
|
- lib/tr8n/cache.rb
|
431
|
-
- lib/tr8n/common_methods.rb
|
432
441
|
- lib/tr8n/config.rb
|
433
442
|
- lib/tr8n/controller_methods.rb
|
434
443
|
- lib/tr8n/dictionary.rb
|
435
444
|
- lib/tr8n/engine.rb
|
436
445
|
- lib/tr8n/exception.rb
|
437
446
|
- lib/tr8n/extender.rb
|
438
|
-
- lib/tr8n/helper_methods.rb
|
439
447
|
- lib/tr8n/ip_address.rb
|
440
448
|
- lib/tr8n/key_registration_exception.rb
|
441
449
|
- lib/tr8n/keyboard_mapping.rb
|
@@ -1,564 +0,0 @@
|
|
1
|
-
<%= tr8n_with_options_tag(:default_locale => 'en-US', :admin => true) do %>
|
2
|
-
<style>
|
3
|
-
h2 {
|
4
|
-
font-weight: bold;
|
5
|
-
}
|
6
|
-
h3 {
|
7
|
-
padding-top: 10px;
|
8
|
-
}
|
9
|
-
.snippet {
|
10
|
-
border: 1px solid #ccc;
|
11
|
-
margin-top:10px;
|
12
|
-
margin-bottom:10px;
|
13
|
-
padding:10px;
|
14
|
-
background-color: #f8f8ff;
|
15
|
-
}
|
16
|
-
.snippet2 {
|
17
|
-
border: 1px solid #ccc;
|
18
|
-
margin-top:10px;
|
19
|
-
margin-bottom:10px;
|
20
|
-
padding:10px;
|
21
|
-
background-color: #fff8f8;
|
22
|
-
}
|
23
|
-
.try_it {
|
24
|
-
font-style:italic;
|
25
|
-
}
|
26
|
-
.toc {
|
27
|
-
margin-left:20px;
|
28
|
-
margin-bottom:20px;
|
29
|
-
list-style-type:upper-roman;
|
30
|
-
}
|
31
|
-
.toc li div {
|
32
|
-
border-bottom:1px dotted #ccc;
|
33
|
-
font-size:16px;
|
34
|
-
}
|
35
|
-
.toc1 {
|
36
|
-
margin-left:20px;
|
37
|
-
list-style-type:lower-roman;
|
38
|
-
}
|
39
|
-
</style>
|
40
|
-
<div style="text-align:center; margin:15px;">
|
41
|
-
<%=image_tag("/tr8n/images/tr8n_logo.png", :style => "height:120px;")%>
|
42
|
-
</div>
|
43
|
-
|
44
|
-
<h2 class="underscore content_hd">
|
45
|
-
<%=tr("Tr8n Translation Engine Integration Guide")%>
|
46
|
-
</h2>
|
47
|
-
|
48
|
-
<div class="content_bd">
|
49
|
-
<h2><%=tr("Table of Content") %></h2>
|
50
|
-
<p>
|
51
|
-
<ul class='toc'>
|
52
|
-
<li><div><a href="#introduction"><%=tr("Introduction") %></a></div>
|
53
|
-
<ul class='toc1'>
|
54
|
-
<li><div><a href="#features"><%=tr("Features") %></a></li>
|
55
|
-
</ul>
|
56
|
-
</li>
|
57
|
-
<li><div><a href="#installation"><%=tr("Installation Instructions") %></a></div>
|
58
|
-
<ul class='toc1'>
|
59
|
-
<li><div><a href="#stand_alone"><%=tr("Running Tr8n as a Stand Alone Application") %></a></li>
|
60
|
-
</ul>
|
61
|
-
</li>
|
62
|
-
<li><div><a href="#configuration"><%=tr("Configuration Instructions") %></a></div>
|
63
|
-
<ul class='toc1'>
|
64
|
-
<li><div><a href="#enabling_features"><%=tr("Enabling Tr8n Features") %></a></li>
|
65
|
-
<li><div><a href="#site_users"><%=tr("Configuring Site and Site Users") %></a></li>
|
66
|
-
<li><div><a href="#caching"><%=tr("Enabling Caching") %></a></li>
|
67
|
-
<li><div><a href="#logger"><%=tr("Enabling Logger") %></a></li>
|
68
|
-
</ul>
|
69
|
-
</li>
|
70
|
-
<li><div><a href="#integration"><%=tr("Integration Instructions") %></a></div>
|
71
|
-
<ul class='toc1'>
|
72
|
-
<li><div><a href="#controllers"><%=tr("Controller And Helper Methods") %></a></li>
|
73
|
-
<li><div><a href="#tags"><%=tr("Tr8n Helper Tags") %></a></li>
|
74
|
-
</ul>
|
75
|
-
</li>
|
76
|
-
<li><div><a href="#next"><%=tr("What's next?") %></a></div></li>
|
77
|
-
</ul>
|
78
|
-
</p>
|
79
|
-
|
80
|
-
<a name="introduction"> </a>
|
81
|
-
<h2><%=tr("Introduction") %></h2>
|
82
|
-
<p>
|
83
|
-
Tr8n translation engine is a rails engine plugin that provides a framework
|
84
|
-
for crowd-source translations and management of any internationalized text
|
85
|
-
throughout any rails based application. The power of the engine comes from
|
86
|
-
its simple and friendly user interface that allows site users to rapidly
|
87
|
-
translate the site into hundreds of languages. The flexible and robust rules
|
88
|
-
engine that powers Tr8n allows for any combinations of language specific
|
89
|
-
rules in any translatable sentence. Users themselves can provide information
|
90
|
-
on what sentences depend on gender rules, number rules or other types of rules
|
91
|
-
supported by the engine. The language specific rules can be registered and
|
92
|
-
managed for any language in the advanced user interface. The engine also
|
93
|
-
provides a set of powerful admin tools that allow admins to manage any
|
94
|
-
aspect of the engine; enabling and disabling its features and monitoring
|
95
|
-
translation process.
|
96
|
-
</p>
|
97
|
-
|
98
|
-
<p>
|
99
|
-
The Tr8n engine is based on a very robust and flexible pluggable architecture where
|
100
|
-
rule types and even syntax of the "tr" tokens can be configured or extended for any application deployment.
|
101
|
-
</p>
|
102
|
-
|
103
|
-
<a name="features"> </a>
|
104
|
-
<h3>Features</h3>
|
105
|
-
<p>Tr8n translation engine comes packed with features, most of which can be enabled and disabled using the configuration file. The features include:</p>
|
106
|
-
<div style="padding-left:20px; padding-bottom:10px;">
|
107
|
-
<ul style="list-style-type:square">
|
108
|
-
<li>Support for over 250 languages</li>
|
109
|
-
<li>Support for left to right and right to left languages (requires css integration)</li>
|
110
|
-
<li>Inline and bulk mode translations</li>
|
111
|
-
<li>Translations based on gender and numeric rules</li>
|
112
|
-
<li>Translations voting system</li>
|
113
|
-
<li>Translations reporting system</li>
|
114
|
-
<li>Software keyboard for over 50 languages</li>
|
115
|
-
<li>Google suggestions for over 50 languages</li>
|
116
|
-
<li>Keyword glossary</li>
|
117
|
-
<li>Translator awards</li>
|
118
|
-
<li>Translations site map</li>
|
119
|
-
<li>Language discussion boards</li>
|
120
|
-
<li>Regional translator management</li>
|
121
|
-
<li>Translator monitoring system</li>
|
122
|
-
<li>Language rule management tools</li>
|
123
|
-
<li>Glossary management tools</li>
|
124
|
-
<li>Help section</li>
|
125
|
-
<li>Administration tools for configuring all aspects of the translations engine</li>
|
126
|
-
<li>And much more...</li>
|
127
|
-
</ul>
|
128
|
-
</div>
|
129
|
-
|
130
|
-
<a name="installation"> </a>
|
131
|
-
<h2>Installation Instructions</h2>
|
132
|
-
<p>
|
133
|
-
Tr8n is mostly self-contained. The only two plugins it depends on are will_paginate created by Mislav Marohnić
|
134
|
-
for results pagination and will_filter created by Michael Berkovich for filtering results in the admin interface.
|
135
|
-
</p>
|
136
|
-
<p>
|
137
|
-
To install the required plugins, run the following commands:
|
138
|
-
|
139
|
-
<div class="snippet">
|
140
|
-
$ script/plugin install git://github.com/mislav/will_paginate.git<br><br>
|
141
|
-
|
142
|
-
$ script/plugin install git://github.com/berk/will_filter.git<br>
|
143
|
-
$ rake will_filter:sync<br>
|
144
|
-
$ rake db:migrate<br>
|
145
|
-
$ cd public; ln -s ../vendor/plugins/will_filter/public/wf wf; cd ..;<br>
|
146
|
-
</div>
|
147
|
-
</p>
|
148
|
-
|
149
|
-
<p>
|
150
|
-
To install, configure and initialize Tr8n engine, run the following commands:
|
151
|
-
|
152
|
-
<div class="snippet">
|
153
|
-
$ script/plugin install git://github.com/berk/tr8n.git<br>
|
154
|
-
$ rake tr8n:sync<br>
|
155
|
-
$ rake db:migrate<br>
|
156
|
-
$ rake tr8n:init<br>
|
157
|
-
$ cd public; ln -s ../vendor/plugins/tr8n/public/tr8n tr8n; cd ..;<br>
|
158
|
-
</div>
|
159
|
-
</p>
|
160
|
-
|
161
|
-
<a name="stand_alone"> </a>
|
162
|
-
<h3>Running Tr8n as a Stand Alone Application</h3>
|
163
|
-
<p>
|
164
|
-
Tr8n can be run as an embedded Rails engine plugin or as a stand-alone application.
|
165
|
-
The stand-alone mode allows you to test various features of the engine before you integrate it into your application.
|
166
|
-
To run Tr8n as a standalone application, execute the following commands:
|
167
|
-
|
168
|
-
<div class="snippet">
|
169
|
-
$ cd vendor/plugins/tr8n<br>
|
170
|
-
$ rake db:migrate<br>
|
171
|
-
$ rake tr8n:init<br>
|
172
|
-
$ script/server
|
173
|
-
</div>
|
174
|
-
</p>
|
175
|
-
<p>
|
176
|
-
The above commands will create a development sqlite3 database in the db folder of tr8n, init the database and run the local web server. Now you can open your browser and
|
177
|
-
point to:
|
178
|
-
|
179
|
-
<div class="snippet">
|
180
|
-
http://localhost:3000/tr8n
|
181
|
-
</div>
|
182
|
-
</p>
|
183
|
-
<p>
|
184
|
-
Congratulations! You are now running Tr8n in the stand-alone mode!<br><br>
|
185
|
-
|
186
|
-
The next section will describe how to configure and run Tr8n in the site-user integrated mode as a Rails plugin engine.
|
187
|
-
</p>
|
188
|
-
|
189
|
-
<a name="configuration"> </a>
|
190
|
-
<h2>Configuration Instructions</h2>
|
191
|
-
<p>
|
192
|
-
Now you are ready to configure and integrate Tr8n engine plugin into your application.
|
193
|
-
When you run the "rake tr8n:sync" command in one of the steps above, the configuration files were copied into your application config
|
194
|
-
folder under the tr8n folder. Those files contain config.yml, which controls the behavior of the engine, enables and disables
|
195
|
-
various engine features and provides date/time localization features. The tr8n folder also contains subfolders with default languages,
|
196
|
-
language rules, language cases, glossaries, shortcuts, etc... Most of the files are self explanatory and contain comments that describe their use.
|
197
|
-
When you run the "rake tr8n:init" command, the contents from the "defaults" files were imported into the database. If you ever want to clean the tr8n database (while developing), you
|
198
|
-
</p>
|
199
|
-
<p>
|
200
|
-
The main Tr8n configuration file is located here:
|
201
|
-
<div class="snippet">
|
202
|
-
config/tr8n/config.yml
|
203
|
-
</div>
|
204
|
-
|
205
|
-
The content of the file is mostly self-explanatory. You can keep most of the defaults. The sections bellow will describe how to change certain aspects of the integration.
|
206
|
-
<br><br>
|
207
|
-
</p>
|
208
|
-
|
209
|
-
<a name="enabling_features"> </a>
|
210
|
-
<h3>Enabling Tr8n Features</h3>
|
211
|
-
<p>
|
212
|
-
The following are the basic features of Tr8n.
|
213
|
-
|
214
|
-
<div class="snippet" style="font-size:11px;">
|
215
|
-
<pre>
|
216
|
-
enable_tr8n: true # enables the engine
|
217
|
-
enable_key_source_tracking: false # builds the site map sources
|
218
|
-
enable_key_caller_tracking: false # tracks all calls to labels with their traces - for debugging only
|
219
|
-
|
220
|
-
enable_glossary_hints: true # shows glossary in the translator
|
221
|
-
enable_software_keyboard: true # shows the soft keyboard icon
|
222
|
-
enable_google_suggestions: true # uses google for suggestions
|
223
|
-
enable_keyboard_shortcuts: true # adds some keyboard shortcuts like ctrl+shift+s
|
224
|
-
enable_dictionary_lookup: true # shows dictionary words definitions
|
225
|
-
|
226
|
-
enable_fallback_languages: true # for example: Catalan can fallback onto Spanish
|
227
|
-
enable_translator_language: true # translator can translate from non-default language
|
228
|
-
|
229
|
-
enable_language_flags: true # shows flag icons next to the languages
|
230
|
-
|
231
|
-
enable_admin_translations: true # registers tr8n admin keys in the system
|
232
|
-
enable_admin_inline_mode: true # allows tr8n engine sections to be inline translated
|
233
|
-
|
234
|
-
enable_language_cases: true # enables support for language cases
|
235
|
-
enable_client_sdk: false # allows javascript to use tr8nProxy object
|
236
|
-
</pre>
|
237
|
-
</div>
|
238
|
-
|
239
|
-
<strong>enable_key_source_tracking</strong> needs to be periodically enabled, especially when new features are added to the site map. If enabled, Tr8n will log the sources for every translation key on the site.
|
240
|
-
<br>
|
241
|
-
</p>
|
242
|
-
|
243
|
-
<a name="site_users"> </a>
|
244
|
-
<h3>Configuring Site and Site Users</h3>
|
245
|
-
<p>
|
246
|
-
Below are the default values from Tr8n config.yml, which are configured for the Tr8n stand alone mode. You will need to modify some of those values to make Tr8n work with your application.
|
247
|
-
|
248
|
-
<div class="snippet" style="font-size:11px;">
|
249
|
-
<pre>
|
250
|
-
site_info:
|
251
|
-
title: Tr8n # site title - provide your site title here
|
252
|
-
contact_email: admin@tr8n.org # contact email for questions about translations
|
253
|
-
current_locale_method: current_locale # application controller method that sets and returns current locale
|
254
|
-
default_url: /tr8n/home # default site url where to redirect the user if Tr8n is disabled
|
255
|
-
default_locale: en-US # locale of the site default language
|
256
|
-
sitemap_path: /config/tr8n/site/sitemap.json # location of the sitemap definition file
|
257
|
-
splash_screen: /tr8n/common/splash_screen # location of the Tr8n splash screen
|
258
|
-
tr8n_layout: tr8n # layout for the tr8n pages
|
259
|
-
tr8n_helpers: [] # if you need to add extra helpers
|
260
|
-
admin_layout: tr8n_admin # layout to be used for the admin user interface
|
261
|
-
admin_helpers: [] # if you need to add extra helpers
|
262
|
-
before_filters: [] # filters from application controller
|
263
|
-
skip_before_filters: [] # filters from application controller
|
264
|
-
after_filters: [] # filters from application controller
|
265
|
-
user_info:
|
266
|
-
enabled: false # if disabled, will fallback onto translators
|
267
|
-
class_name: User # class name for the User object type
|
268
|
-
current_user_method: current_user # provides current user object
|
269
|
-
methods: # User object methods mapping
|
270
|
-
id: id
|
271
|
-
name: name
|
272
|
-
gender: gender
|
273
|
-
admin: admin?
|
274
|
-
guest: guest?
|
275
|
-
mugshot: mugshot
|
276
|
-
link: link
|
277
|
-
locale: locale
|
278
|
-
</pre>
|
279
|
-
</div>
|
280
|
-
|
281
|
-
|
282
|
-
Here is the modified version that could fit your application. The modified items are marked in bold.
|
283
|
-
|
284
|
-
<div class="snippet2" style="font-size:11px;">
|
285
|
-
<pre>
|
286
|
-
site_info:
|
287
|
-
<strong>title: My Site Title</strong>
|
288
|
-
<strong>contact_email: translations@mysitedomain.com</strong>
|
289
|
-
current_locale_method: current_locale
|
290
|
-
<strong>default_url: /</strong>
|
291
|
-
default_locale: en-US
|
292
|
-
sitemap_path: /config/tr8n/site/sitemap.json
|
293
|
-
splash_screen: /tr8n/common/splash_screen
|
294
|
-
<strong>tr8n_layout: application</strong>
|
295
|
-
tr8n_helpers: []
|
296
|
-
<strong>admin_layout: admin</strong>
|
297
|
-
admin_helpers: []
|
298
|
-
before_filters: []
|
299
|
-
skip_before_filters: []
|
300
|
-
after_filters: []
|
301
|
-
user_info:
|
302
|
-
<strong>enabled: true</strong>
|
303
|
-
class_name: User
|
304
|
-
current_user_method: current_user
|
305
|
-
<strong><i>methods:
|
306
|
-
id: id
|
307
|
-
name: name
|
308
|
-
gender: gender
|
309
|
-
admin: admin?
|
310
|
-
guest: guest?
|
311
|
-
mugshot: mugshot
|
312
|
-
link: link
|
313
|
-
locale: locale
|
314
|
-
</i></strong>
|
315
|
-
</pre>
|
316
|
-
</div>
|
317
|
-
|
318
|
-
|
319
|
-
You need to map your User object methods to the methods defined in the config file under the user_info section.
|
320
|
-
Alternatively, you could overload any of the config properties in the Tr8n::Config class. You can do this by creating a new
|
321
|
-
|
322
|
-
<div class="snippet">
|
323
|
-
config/initializers/tr8n.rb
|
324
|
-
</div>
|
325
|
-
|
326
|
-
And overloading any of the Tr8n::Config methods, as follows:
|
327
|
-
|
328
|
-
<div class="snippet">
|
329
|
-
<pre>
|
330
|
-
Rails.configuration.after_initialize do
|
331
|
-
|
332
|
-
class Tr8n::Config
|
333
|
-
def self.enabled?
|
334
|
-
true
|
335
|
-
end
|
336
|
-
|
337
|
-
def self.user_name(user)
|
338
|
-
user.name
|
339
|
-
end
|
340
|
-
|
341
|
-
def self.user_gender(user)
|
342
|
-
user.gender
|
343
|
-
end
|
344
|
-
|
345
|
-
...
|
346
|
-
end
|
347
|
-
|
348
|
-
end
|
349
|
-
</pre>
|
350
|
-
</div>
|
351
|
-
</p>
|
352
|
-
|
353
|
-
<p>
|
354
|
-
The <strong>current_locale</strong> method should not only return back the locale, but should also be able to store and preserve the locale.
|
355
|
-
If the method is not defined, then Tr8n will fallback onto the default implementation which stores the selected locale in the session.
|
356
|
-
|
357
|
-
You can implement your own method of determining and returning the locale of the site. For example, the locale can be configured as a subdomain or a site extension.
|
358
|
-
Below is an example of the current_locale method that sets the locale from a parameter, uses user's locale or uses browser's preffered locale:
|
359
|
-
|
360
|
-
<div class="snippet">
|
361
|
-
<pre>
|
362
|
-
def current_locale
|
363
|
-
if params[:locale]
|
364
|
-
session[:locale] = params[:locale]
|
365
|
-
session[:save_locale] = true
|
366
|
-
elsif !current_user.guest? and current_user.locale != nil
|
367
|
-
session[:locale] = current_user.locale
|
368
|
-
elsif session[:locale] == nil
|
369
|
-
session[:locale] = tr8n_user_preffered_locale
|
370
|
-
session[:save_locale] = (session[:locale] != Tr8n::Config.default_locale)
|
371
|
-
end
|
372
|
-
|
373
|
-
if session[:save_locale] and not current_user.user.guest?
|
374
|
-
current_user.changed_language!(session[:locale])
|
375
|
-
session[:save_locale] = nil
|
376
|
-
end
|
377
|
-
|
378
|
-
session[:locale]
|
379
|
-
end
|
380
|
-
</pre>
|
381
|
-
</div>
|
382
|
-
|
383
|
-
<strong>tr8n_user_preffered_locale</strong> returns back the first available locale supported by Tr8n that the browser has requested in the order of the browser's language preferences.
|
384
|
-
|
385
|
-
<br><br>
|
386
|
-
There are a few other settings in config.yml that you may want to review. Those settings will be covered in the later sections.
|
387
|
-
</p>
|
388
|
-
|
389
|
-
<a name="caching"> </a>
|
390
|
-
<h3>Enabling Caching</h3>
|
391
|
-
<p>
|
392
|
-
It is best to run Tr8n with some kind of caching support. One of the best solutions is to use Memcached for caching.
|
393
|
-
Tr8n comes with support for any Rails caching methods as well as a mechanism to integrate a custom caching adapter to address your specific needs.
|
394
|
-
|
395
|
-
<div class="snippet">
|
396
|
-
<pre>
|
397
|
-
caching:
|
398
|
-
enabled: true
|
399
|
-
adapter: ActiveSupport::Cache
|
400
|
-
store: [mem_cache_store, 'localhost:11211']
|
401
|
-
version: 1 # you can change the version to invalidate the cache
|
402
|
-
</pre>
|
403
|
-
</div>
|
404
|
-
|
405
|
-
If you choose to use the Rails caching support, then use the ActiveSupport::Cache as the adapter. You can choose any one of the following cache stores:
|
406
|
-
memory_store, file_store, drb_store, [mem_cache_store, 'localhost:11211']
|
407
|
-
<br><br>
|
408
|
-
|
409
|
-
If you have a custom cache solution, you can implement a custom adapter class and provide your custom implementation. The class must implement the following methods:
|
410
|
-
<div class="snippet">
|
411
|
-
<pre>
|
412
|
-
class CustomCacheAdapter
|
413
|
-
|
414
|
-
def self.fetch(key, options = {})
|
415
|
-
CACHE.get_or_add(key) do
|
416
|
-
yield
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
def self.delete(key, options = nil)
|
421
|
-
CACHE.delete(key)
|
422
|
-
end
|
423
|
-
|
424
|
-
end
|
425
|
-
</pre>
|
426
|
-
</div>
|
427
|
-
|
428
|
-
Then you can set the caching adapter to your custom class name.
|
429
|
-
<br><br>
|
430
|
-
The Tr8n version parameter is used to expire and rotate cached values. For example, if you have removed a lot of old keys from your system, you may want to increment the cache version.
|
431
|
-
This will remove the old values from the cache and replace them with the new values. When a translation key is loaded into cache, Tr8n will aslo update the verified_at timestamp of the key.
|
432
|
-
This way you can keep track of which keys have been accessed and when. So you can periodically delete the old, unused keys.
|
433
|
-
</p>
|
434
|
-
|
435
|
-
<a name="logger"> </a>
|
436
|
-
<h3>Enabling Logger</h3>
|
437
|
-
<p>
|
438
|
-
By default, Tr8n will use its own logger. If you set it to false, it will use default Rails logger.
|
439
|
-
<div class="snippet">
|
440
|
-
<pre>
|
441
|
-
logger:
|
442
|
-
enabled: true
|
443
|
-
log_path: log/tr8n.log # location of the log file
|
444
|
-
enable_paranoia_mode: true # logs every translator action
|
445
|
-
</pre>
|
446
|
-
</div>
|
447
|
-
</p>
|
448
|
-
|
449
|
-
<a name="integration"> </a>
|
450
|
-
<h2>Integration Instructions</h2>
|
451
|
-
<p>The following sections will give a quick overview for how to integrate and customize tr8n into your rails application.</p>
|
452
|
-
|
453
|
-
<a name="controllers"> </a>
|
454
|
-
<h3>Controller And Helper Methods</h3>
|
455
|
-
<p>
|
456
|
-
Add the following include directive to the ApplicationController class:
|
457
|
-
<div class="snippet">
|
458
|
-
class ApplicationController < ActionController::Base<br>
|
459
|
-
<strong>include Tr8n::CommonMethods</strong><br>
|
460
|
-
...<br>
|
461
|
-
end
|
462
|
-
</div>
|
463
|
-
</p>
|
464
|
-
<p>
|
465
|
-
Add the following include directive to the ApplicationHelper module:
|
466
|
-
<div class="snippet">
|
467
|
-
module ApplicationHelper<br>
|
468
|
-
<strong>include Tr8n::HelperMethods</strong><br>
|
469
|
-
<strong>include Wf::HelperMethods</strong><br>
|
470
|
-
...<br>
|
471
|
-
end
|
472
|
-
</div>
|
473
|
-
|
474
|
-
The above instructions will include all of the necessary helper methods so that Tr8n can be used in all of the controllers and views of your application.
|
475
|
-
</p>
|
476
|
-
|
477
|
-
<a name="tags"> </a>
|
478
|
-
<h3>Tr8n Helper Tags</h3>
|
479
|
-
<p>
|
480
|
-
For the purpose of this excercise we will assume that you have a global layout file defined in <strong>app/views/layouts/application.html.erb</strong> that, in its simplistic form, looks something like this:
|
481
|
-
|
482
|
-
<div class="snippet">
|
483
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><br>
|
484
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><br>
|
485
|
-
<head><br>
|
486
|
-
</head><br>
|
487
|
-
<body><br>
|
488
|
-
<%= @content_for_layout %><br>
|
489
|
-
</body><br>
|
490
|
-
</html><br>
|
491
|
-
</div>
|
492
|
-
|
493
|
-
There are many different ways you could integrate the language selector and tools into your application. Tr8n comes with a number of tags that can help you integrate the various scripts.
|
494
|
-
</p>
|
495
|
-
<p>
|
496
|
-
Note: All of the Tr8n JavaScripts are framework independent and it shouldn't matter what framework you use for your application.
|
497
|
-
</p>
|
498
|
-
|
499
|
-
<p>
|
500
|
-
<strong>tr8n_scripts_tag</strong> - embeds tr8n javascripts and stylesheets necessary for the inline translator to work. It also contains translation suggestions, virtual keyboard
|
501
|
-
and shortucts scripts. This is the only required tag that must be included on all of the traslatable pages.
|
502
|
-
<br><br>
|
503
|
-
|
504
|
-
<strong>tr8n_language_selector_tag</strong> - embeds the standard Tr8n language selector with links to enable/disable inline translations, translators tools, adminstrations tools and help.
|
505
|
-
This tag is usually used in the top right corner of the application.
|
506
|
-
<br><br>
|
507
|
-
|
508
|
-
<strong>tr8n_translator_login_tag</strong> - embeds translator login and language selector. This tag is only useful when the site does not have its own user registration mechanism.
|
509
|
-
<br><br>
|
510
|
-
|
511
|
-
<strong>tr8n_language_strip_tag</strong> - embeds language strip with the featured languages. Featured languages can be configured using the admin tool. This tag is usually used at the bottom
|
512
|
-
of the application.
|
513
|
-
|
514
|
-
<br><br>
|
515
|
-
|
516
|
-
Once you add the above tags, your layout file will look something like this:
|
517
|
-
|
518
|
-
<div class="snippet">
|
519
|
-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><br>
|
520
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><br>
|
521
|
-
<head><br>
|
522
|
-
<%= tr8n_scripts_tag %><br>
|
523
|
-
</head><br>
|
524
|
-
<body><br>
|
525
|
-
<div style="float:right"><br>
|
526
|
-
<%= tr8n_language_selector_tag %><br>
|
527
|
-
</div><br><br>
|
528
|
-
<%= @content_for_layout %><br><br>
|
529
|
-
<%= tr8n_language_strip_tag %><br>
|
530
|
-
</body><br>
|
531
|
-
</html><br>
|
532
|
-
</div>
|
533
|
-
|
534
|
-
Now you are ready to add and translate your first label. Open up any view from any controller (make sure that the view's layout has the tags from the examples above) and add the following line:
|
535
|
-
|
536
|
-
<div class="snippet">
|
537
|
-
<%=tr("Hello World", "My first translatable greeting to the world!")%>
|
538
|
-
</div>
|
539
|
-
|
540
|
-
If your site supports users and you would like to use Tr8n in the site user integrated mode, then you must implement your own login/registration mechanism as well as follow the steps described in the
|
541
|
-
"Configuring Site User" section of this document. Tr8n will automatically determine if your user has logged in and will give the appropriate options for enabling/disabling inline translations.
|
542
|
-
<br><br>
|
543
|
-
|
544
|
-
On the other hand, if you want to keep Tr8n translators separate from your site users, you can use the tr8n_translator_login_tag or the following URLs for registering translators and logging into Tr8n.
|
545
|
-
|
546
|
-
<div class="snippet">
|
547
|
-
http://localhost:3000/tr8n/login<br>
|
548
|
-
http://localhost:3000/tr8n/login/register<br>
|
549
|
-
http://localhost:3000/tr8n/login/out<br>
|
550
|
-
</div>
|
551
|
-
The Tr8n login mechanism is very simplistic and it is there to just get you started. So it is best that you implement a better, more secure user authentication mechanism and integrate the site users with Tr8n.
|
552
|
-
Try registering a new user, changing a language and translating the label.
|
553
|
-
|
554
|
-
<br><br>
|
555
|
-
Now you are ready to try more advanced translation options.
|
556
|
-
</p>
|
557
|
-
|
558
|
-
<a name="next"> </a>
|
559
|
-
<h2>What's next?</h2>
|
560
|
-
|
561
|
-
Cnogratulations! You have completed the first part of the integration guide. Now read on about <%=link_to("Tr8n Label Internationalization", "/tr8n/home/tokens")%>.
|
562
|
-
|
563
|
-
</div>
|
564
|
-
<% end %>
|