tr8n 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,668 +0,0 @@
1
- <%= tr8n_with_options_tag(:default_locale => 'en-US', :admin => true) do %>
2
-
3
- <style>
4
- h2 {
5
- font-weight: bold;
6
- }
7
- h3 {
8
- padding-top: 10px;
9
- }
10
- .snippet {
11
- border: 1px solid #ccc;
12
- margin-top:10px;
13
- margin-bottom:10px;
14
- padding:10px;
15
- background-color: #f8f8ff;
16
- }
17
- .snippet2 {
18
- border: 1px solid #ccc;
19
- margin-top:10px;
20
- margin-bottom:10px;
21
- padding:10px;
22
- background-color: #fff8f8;
23
- }
24
- .try_it {
25
- font-style:italic;
26
- }
27
- .toc {
28
- margin-left:20px;
29
- margin-bottom:20px;
30
- list-style-type:upper-roman;
31
- }
32
- .toc li div {
33
- border-bottom:1px dotted #ccc;
34
- font-size:16px;
35
- }
36
- .toc1 {
37
- margin-left:20px;
38
- list-style-type:lower-roman;
39
- }
40
- </style>
41
- <div style="text-align:center; margin:15px;">
42
- <%=image_tag("/tr8n/images/tr8n_logo.png", :style => "height:120px;")%>
43
- </div>
44
-
45
- <h2 class="underscore content_hd">
46
- <%=tr("Tr8n Rules Engine Configuration")%>
47
- </h2>
48
-
49
- <div class="content_bd">
50
- <h2><%=tr("Table of Content") %></h2>
51
- <p>
52
- <ul class='toc'>
53
- <li><div><a href="#introduction"><%=tr("Introduction") %></a></div>
54
- </li>
55
- <li><div><a href="#context_rules"><%=tr("Language Context Rules") %></a></div>
56
- <ul class='toc1'>
57
- <li><div><a href="#numeric_rules"><%=tr("Numeric Rules") %></a></li>
58
- <li><div><a href="#gender_rules"><%=tr("Gender Rules") %></a></li>
59
- <li><div><a href="#list_rules"><%=tr("List Rules") %></a></li>
60
- <li><div><a href="#date_rules"><%=tr("Date Rules") %></a></li>
61
- <li><div><a href="#value_rules"><%=tr("Value Rules") %></a></li>
62
- </ul>
63
- </li>
64
- <li><div><a href="#context_rules"><%=tr("Language Case Rules") %></a></div></li>
65
- </ul>
66
- </p>
67
-
68
- <a name="introduction">&nbsp;</a>
69
- <h2><%=tr("Introduction") %></h2>
70
- <p>
71
- Tr8n translation engine is a rails engine plugin that provides a framework
72
- for crowd-source translations and management of any internationalized text
73
- throughout any rails based application. The power of the engine comes from
74
- its simple and friendly user interface that allows site users to rapidly
75
- translate the site into hundreds of languages. The flexible and robust rules
76
- engine that powers Tr8n allows for any combinations of language specific
77
- rules in any translatable sentence. Users themselves can provide information
78
- on what sentences depend on gender rules, number rules or other types of rules
79
- supported by the engine. The language specific rules can be registered and
80
- managed for any language in the advanced user interface.
81
- </p>
82
-
83
- <p>
84
- There are two types of rules supported by Tr8n:
85
- <div style="padding-left:20px; padding-bottom:10px;">
86
- <ul style="list-style-type:square">
87
- <li>Language context rules that define the context for translations.</li>
88
- <li>Language case rules that evaluate and modify token values.</li>
89
- </ul>
90
- </div>
91
- </p>
92
-
93
- <p>
94
- This document provides details on how to configure rules for various languages and shows examples on how those rules are used by the translators.
95
- </p>
96
-
97
- <a name="context_rules">&nbsp;</a>
98
- <h2>Language Context Rules</h2>
99
- <p>
100
- Language context rules are used to define a context for any translation of the original phrase. The easiest way to understand it is to start with a simple example.
101
-
102
- <div class="snippet">
103
- tr("You have {count||message}", "Inbox count label", :count => 5)
104
- </div>
105
-
106
- <i>Note: In the above example, we used a transform token to make it easy to evaluate the numeric rule for the base language (which is English in our case). More on it later.<br><br>
107
- </i>
108
-
109
- In many languages the translated word "messages" depends on the value of the token {count}.
110
- In languages, like English, there are only two context rules that are necessary to correctly translate the above phrase:
111
- <br><br>
112
- <div style="padding-left:20px; padding-bottom:10px;">
113
- <ul style="list-style-type:square">
114
- <li>Rule 1: {count} is 1</li>
115
- <li>Rule 2: {count} is not 1</li>
116
- </ul>
117
- </div>
118
-
119
- When a translator opens the translation window for the above phrase, he/she can indicate that the phrase translations depend on the context rules (based on some tokens) and
120
- provide the translation for each of the rule:<br>
121
- <div class="snippet">
122
- "You have 1 message!"<br>
123
- Context: count is 1<br><br>
124
-
125
- "You have 2 messages!"<br>
126
- Context: count is not 1<br>
127
- </div>
128
-
129
- But this is not the case with other language. For instant, many of the Slavic languages, like Russian, has 3 or more rules for number based tokens.
130
-
131
- Lets use the following code and try translating it using Russian language:
132
- <div class="snippet">
133
- &lt;% 0.upto(5) do |i| %><br><br>
134
- &nbsp;&nbsp;&nbsp;&nbsp; &lt;%= tr("You have {count||message}", "Inbox count label", :count => i) %><br><br>
135
- &lt;% end %><br>
136
- </div>
137
-
138
- <br>
139
- Now follow the steps below and try translating the following block:
140
-
141
- <div class="snippet2">
142
- <% 0.upto(5) do |i| %>
143
- <%= tr("You have {count||message}", "Inbox count label", :count => i) %><br>
144
- <% end %>
145
- </div>
146
-
147
- <div style="padding-left:20px; padding-bottom:10px;">
148
- <ul style="list-style-type:decimal;">
149
- <li>Make sure you are a registered user and have logged into the site</li>
150
- <li>Choose a language other than English</li>
151
- <li>Press Ctrl+Shift+I to enable the inline translations or choose that options from the language selector.</li>
152
- <li>Right-mouse-click on any one of the highlighted rows above to open the translator window</li>
153
- <li>Click on the "generate context rules for this phrase" link:<br><br>
154
- <%=image_tag("/tr8n/images/examples/numeric_rules_1.png")%><br><br>
155
- </li>
156
- <li>Check the number dependency checkbox in the count token row:<br><br>
157
- <%=image_tag("/tr8n/images/examples/numeric_rules_2.png")%><br><br>
158
- </li>
159
- <li>Click "Continue..." button to see the translation option for each context rule available for the language:<br><br>
160
- <%=image_tag("/tr8n/images/examples/numeric_rules_3.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
161
- </li>
162
- </ul>
163
- </div>
164
-
165
- Based on the language you chose, you will get a list of pre-generated default translations for each context rule for the given phrase.
166
- In the above example, we chose the Russian language, which like some Slavic languages, has three rules for number dependent tokens.
167
- <br><br>
168
- If you followed the instructions above and chose Russian language, you should see the above block looking something like this:<br><br>
169
- <%=image_tag("/tr8n/images/examples/numeric_rules_4.png", :style => "width:800px;")%><br><br>
170
-
171
- Good job! By this point you pretty much have an idea of how the rules engine works.<br><br>
172
-
173
- Lets take a look now at the various rules that Tr8n rules engine comes with.
174
- </p>
175
-
176
- <a name="numeric_rules">&nbsp;</a>
177
- <h3>Numeric Rules</h3>
178
- <p>
179
- The example above was using the numeric rules dependency. It showed how the translators deal with the rules when they translate the sentence,
180
- but what it didn't show was the following:
181
-
182
- <ul style="padding-left:20px; list-style-type:square;">
183
- <li>Where did Tr8n get the 3 rules defined for Russian language?</li>
184
- <li>How on Earth did Tr8n know that the {count} token was dependant on numeric rules?</li>
185
- <li>How does it evaluate the rules at Runtime to get the appropritate translation for the given phrase?</li>
186
- </ul>
187
- <br><br>
188
-
189
- Let's start from the beginning. Tr8n engine has three modes: user facing functions, language manager functions and administrative functions.
190
- User facing function showed everything that we've done during the translation process in the above example. Language manager function is what we are going to look at right now.
191
- Admin facing functions is what only site administrators can see. We will look into it later.
192
- <br><br>
193
-
194
- If you are a language manager for any particular language, then you have access to the following interface of that language:<br><br>
195
- <%=image_tag("/tr8n/images/examples/language_manager_1.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
196
-
197
- There are a few different tools that language managers can use to change each language behavior. In our case, let's concentrate on the Context Rules section.<br><br>
198
-
199
- <%=image_tag("/tr8n/images/examples/context_rules_1.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
200
-
201
- If you click on the edit button on the top right corner, you will enter the edit mode of the context rules:<br><br>
202
- <%=image_tag("/tr8n/images/examples/context_rules_2.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
203
-
204
- In that screen language managers can change rule definitions for each rule type. As it was mentioned earlier, in English language the rules would simply be:
205
-
206
- <div style="padding-left:20px; padding-bottom:10px;">
207
- <ul style="list-style-type:square">
208
- <li>is 1</li>
209
- <li>is not 1</li>
210
- </ul>
211
- </div>
212
-
213
- <strong>Number Rule Definition</strong><br><br>
214
- <div style="padding-left:20px; padding-bottom:10px;">
215
- <ul style="list-style-type:square">
216
- <li>Number rule can be simple or complex. You can use "more" and "less" links to use the double conditions for any rule line.</li>
217
- <li>The first operation options are: "is", "is not", "ends in", "does not end in"</li>
218
- <li>The linking operator options are: "and", "or"</li>
219
- <li>The last operation options are: "is", "is not", "ends in", "does not end in"</li>
220
- </ul>
221
- </div>
222
-
223
- We have answered the first question of where Tr8n got the rules. Now let's look at how Tr8n knew about the token-rule dependency. <br><br>
224
-
225
- <strong>Number Rule Configuration</strong><br><br>
226
-
227
- Tr8n Rules engine itself does not know and really care about what rules it has and what it should do with them. The rules of Tr8n can be extended, modified, added and removed by the developers.
228
- Take a look at the Rule Engine section in the <strong>config/tr8n/config.yml</strong> file:
229
-
230
- <div class="snippet" style="font-size:11px;">
231
- <pre>
232
- #############################################################################
233
- # Rules Engine Settings
234
- #############################################################################
235
- rules_engine:
236
- <strong>language_rule_classes: [Tr8n::NumericRule, Tr8n::GenderRule, Tr8n::GenderListRule, Tr8n::DateRule, Tr8n::ValueRule]</strong>
237
- data_token_classes: [Tr8n::Tokens::DataToken, Tr8n::Tokens::HiddenToken, Tr8n::Tokens::MethodToken, Tr8n::Tokens::TransformToken]
238
- decoration_token_classes: [Tr8n::Tokens::DecorationToken]
239
- allow_nil_token_values: true
240
- <strong>numeric_rule:
241
- token_suffixes: [count, num, age, hours, minutes, years, seconds]
242
- object_method: to_i
243
- </strong>gender_rule:
244
- token_suffixes: [user, profile, actor, target, partner, parent, child, sibling, manager]
245
- object_method: gender
246
- method_values:
247
- female: female
248
- male: male
249
- neutral: neutral
250
- unknown: unknown
251
- gender_list_rule:
252
- object_method: size
253
- token_suffixes: [list]
254
- date_rule:
255
- token_suffixes: [date]
256
- object_method: to_date
257
- value_rule:
258
- token_suffixes: *
259
- object_method: to_s
260
- </pre>
261
- </div>
262
-
263
- The most important parts of the file that are applicable to the Number Rule are in bold. When Tr8n boots up for the first time, it looks at the list of rule classes under the
264
- language_rule_classes key and loads the classes it needs. Each Rule class extends the basic Tr8n::LanguageRule class, which provides the basic rule behavior.
265
- The rule configuration options and UI are provided by the rules themselves. So it is fairly easy to add a new rule to the engine.
266
- <br><br>
267
-
268
- Since Tr8n comes with the 6 default rules, I have added sections in the rules_engine config section where these rules can be configured. Each rule may need some ability to be customized for
269
- the site where Tr8n will be used.
270
- <br><br>
271
-
272
- <strong>Number Rule</strong> is implemented by the <strong>Tr8n::NumericRule</strong> class and uses the <strong>numeric_rule</strong> section of the rules_engine configuration.
273
- <br><br>
274
-
275
- <div style="padding-left:20px; padding-bottom:10px;">
276
- <ul style="list-style-type:square">
277
- <li><strong>token_suffixes</strong> indicates the set of token names that have numerical values and can be translated using numeric context rule</li>
278
- <li><strong>object_method</strong> indicates the method that must be applied on the token object in order to get its numerical value</li>
279
- </ul>
280
- </div>
281
-
282
- This means that any of the following tokens will give user an option to translate the phrase based on the numeric value of the token: {count}, {num}, {message_num}, {user_count}, etc...
283
-
284
- Notice that in our above example we used a simple number for the token value. It worked great because, in Ruby, the numbers are objects that respond to to_i method as well:
285
-
286
- <div class="snippet">
287
- tr("You have {count||message}", "Inbox count label", :count => 5)
288
- </div>
289
-
290
- But the value of the {count} could have been a string or any other object, as long as it implemented the to_i method. If your site has other conventions, you can easily change the
291
- numeric_rule definition and everything would still work.
292
-
293
- </p>
294
-
295
- <a name="gender_rules">&nbsp;</a>
296
- <h3>Gender Rules</h3>
297
- <p>
298
- Consider the following example:
299
-
300
- <div class="snippet">
301
- tr("Dear {user},", "Reference to a user in a heading of an email", :user => [current_user, :name])<br><br>
302
- tr("{user} updated {user| his, her} profile.", "Newsfeed story heading", :user => [some_user, :name])<br><br>
303
- tr("{user| Added On:}", "Label for when the user was added to the site", :user => some_user)<br><br>
304
- </div>
305
-
306
- All of the above examples have dependency on the gender of the {user} token. Each sentence will have 2 or 3 translations based on the rule definition of the language the phrase is translated to.
307
-
308
- <br><br>
309
- Change your language, enable inline translations and try translating the following sentences yourself:
310
- <div class="snippet2">
311
- <%= tr("Dear {user},", "Reference to a user in a heading of an email", :user => [Tr8n::Config.current_user, :name]) %>
312
- <br><br>
313
- <%= tr("{user} updated {user| his, her} profile.", "Newsfeed story heading", :user => [Tr8n::Config.current_user, :name]) %>
314
- <br><br>
315
- <%= tr("{user| Added On:}", "Label for when the user was added to the site", :user => Tr8n::Config.current_user) %>
316
- </div>
317
-
318
-
319
- Let's take the second example and look at what it would be translated to in Russian:
320
- <br><br>
321
- <%=image_tag("/tr8n/images/examples/gender_rules_1.png", :style =>"vertical-align:top; padding-right:15px;")%>
322
- <%=image_tag("/tr8n/images/examples/gender_rules_2.png", :style =>"vertical-align:top")%><br><br>
323
-
324
- Translating the above sentece into Russian will require setting up a dependency on the {user} token. Russian language was configured to have 3 rules to hande male, female and unknown gender cases.<br><br>
325
- <%=image_tag("/tr8n/images/examples/gender_rules_3.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
326
-
327
- Some languages can treat unknown genders as male genders. The gender rules for that language can simply state:
328
- <div style="padding-left:20px; padding-bottom:10px;">
329
- <ul style="list-style-type:square">
330
- <li>user is a female</li>
331
- <li>user is not a female</li>
332
- </ul>
333
- </div>
334
-
335
- <br>
336
- <strong>Gender Rule Definition</strong><br><br>
337
- <div style="padding-left:20px; padding-bottom:10px;">
338
- <ul style="list-style-type:square">
339
- <li>A rule consists of 2 parts: operator and gender.</li>
340
- <li>The operator options are: "is", "is not"</li>
341
- <li>The gender options are: "a male", "a female", "neutral", "unknown"</li>
342
- </ul>
343
- </div>
344
-
345
- <br>
346
- <strong>Gender Rule Configuration</strong><br>
347
- <div class="snippet" style="font-size:11px;">
348
- <pre>
349
- rules_engine:
350
- ...
351
- <strong>gender_rule:
352
- token_suffixes: [user, profile, actor, target, partner, parent, child, sibling, manager]
353
- object_method: gender
354
- method_values:
355
- female: female
356
- male: male
357
- neutral: neutral
358
- unknown: unknown</strong>
359
- ...
360
- </pre>
361
- </div>
362
-
363
- <strong>Gender Rule</strong> is implemented by the <strong>Tr8n::GenderRule</strong> class and uses the <strong>gender_rule</strong> section of the rules_engine configuration.
364
- <br><br>
365
- <div style="padding-left:20px; padding-bottom:10px;">
366
- <ul style="list-style-type:square">
367
- <li><strong>token_suffixes</strong> indicates the set of token names that can be translated using gender context rule</li>
368
- <li><strong>object_method</strong> indicates the method that must be applied on the token object in order to get its gender value</li>
369
- <li><strong>method_values</strong> maps the return values from the object_method that would tell the rule if it met the evaluation criteria</li>
370
- </ul>
371
- </div>
372
- </p>
373
-
374
- <a name="list_rules">&nbsp;</a>
375
- <h3>List Rules</h3>
376
- <p>
377
- Consider the following examples:
378
-
379
- <div class="snippet">
380
- user1 = User.new(:name => "Michael", :gender => 'male')<br>
381
- user2 = User.new(:name => "Amos", :gender => 'male')<br>
382
- user3 = User.new(:name => "Tina", :gender => 'female')<br>
383
- users = [user1, user2, user3]<br><br>
384
-
385
- tr("{user_list} updated {user_list| his profile, her profile, their profiles}.", "Newsfeed story title", :user_list => [users, :name])<br><br>
386
- tr("{user_list} updated {user_list| his profile, her profile, their profiles}.", "Newsfeed story title", :user_list => [[user1], :name])<br><br>
387
- tr("{user_list|| likes, like} this post.", "Newsfeed story title", :user_list => [users, :name])<br><br>
388
- tr("{user_list|| likes, like} this post.", "Newsfeed story title", :user_list => [[user1], :name])<br><br>
389
- </div>
390
-
391
- <br>
392
- Change your language, enable inline translations and try translating the following sentences yourself:
393
- <div class="snippet2">
394
- <%
395
- user1 = Tr8n::Translator.new(:name => "Michael", :gender => 'male')
396
- user2 = Tr8n::Translator.new(:name => "Amos", :gender => 'male')
397
- user3 = Tr8n::Translator.new(:name => "Tina", :gender => 'female')
398
- users = [user1, user2, user3]
399
- %>
400
- <%= tr("{user_list} updated {user_list| his profile, her profile, their profiles}.", "Newsfeed story title", :user_list => [users, :name]) %><br><br>
401
- <%= tr("{user_list} updated {user_list| his profile, her profile, their profiles}.", "Newsfeed story title", :user_list => [[user1], :name]) %><br><br>
402
-
403
- <%= tr("{user_list|| likes, like} this post.", "Newsfeed story title", :user_list => [users, :name]) %><br><br>
404
- <%= tr("{user_list|| likes, like} this post.", "Newsfeed story title", :user_list => [[user1], :name]) %><br><br>
405
- </div>
406
-
407
- <br>
408
- As you can tell, there is something interesting going on here. Overall, there is nothing new. We are just using the transform tokens. The above examples only registered two
409
- phrases in the system. But they are very powerful. List tokens have special notations and we are going to look at them in a little bit.
410
-
411
- Let's take the first example and look at what it would be translated to in Russian:
412
- <br><br>
413
- <%=image_tag("/tr8n/images/examples/list_rules_1.png", :style =>"vertical-align:top; padding-right:15px;")%>
414
- <%=image_tag("/tr8n/images/examples/list_rules_2.png", :style =>"vertical-align:top")%><br><br>
415
-
416
- Translating the above sentece into Russian will require setting up a dependency on the {user_list} token.
417
- Russian language was configured to have 4 rules to hande male, female, unknown gender cases for a single element in the list and one rule for plural case.<br><br>
418
- <%=image_tag("/tr8n/images/examples/list_rules_3.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
419
-
420
- Some languages, like Hebrew, can specify the genders for the plural cases as well:
421
- <div style="padding-left:20px; padding-bottom:10px;">
422
- <ul style="list-style-type:square">
423
- <li>user_list contains at least 2 elements that are all male</li>
424
- <li>user_list contains at least 2 elements that are all female</li>
425
- <li>user_list contains at least 2 elements that are of mixed gender</li>
426
- </ul>
427
- </div>
428
-
429
- <br>
430
- <strong>List Rule Definition</strong><br><br>
431
- <div style="padding-left:20px; padding-bottom:10px;">
432
- <ul style="list-style-type:square">
433
- <li>List rule can be simple or complex. You can use "more" and "less" links to use the double conditions for any rule line.</li>
434
- <li>First operator options: "contains"</li>
435
- <li>First operator values: "one element", "at least 2 elements"</li>
436
- <li>Second operator options: "that is", "that is not", "that are", "that are not"</li>
437
- <li>Second operator values: "male", "female", "unknown", "neutral", "all male", "all female", "of mixed gender"</li>
438
- </ul>
439
- </div>
440
-
441
- <br>
442
- <strong>List Rule Configuration</strong><br>
443
- <div class="snippet" style="font-size:11px;">
444
- <pre>
445
- rules_engine:
446
- ...
447
- <strong>gender_list_rule:
448
- object_method: size
449
- token_suffixes: [list]</strong>
450
- ...
451
- </pre>
452
- </div>
453
-
454
- <strong>List Rule</strong> is implemented by the <strong>Tr8n::GenderListRule</strong> class and uses the <strong>gender_list_rule</strong> section of the rules_engine configuration.
455
- It is important to note that the list rule works together with the gender rule to use the gender method configurations.
456
- <br><br>
457
- <div style="padding-left:20px; padding-bottom:10px;">
458
- <ul style="list-style-type:square">
459
- <li><strong>token_suffixes</strong> indicates the set of token names that can be translated using gender context rule</li>
460
- <li><strong>object_method</strong> indicates the method that must be applied on the token object in order to get its gender value</li>
461
- </ul>
462
- </div>
463
-
464
-
465
- <br>
466
- <strong>List View Options</strong><br><br>
467
-
468
- When a token contains a collection of values instead of a single value (wether it needs to be rule dependent or not) it has some nice extra features in terms of how it can be
469
- presented to the user.
470
- <div class="snippet" style="font-size:11px;">
471
- <pre>
472
- ##############################################################################
473
- #
474
- # tr("Hello {user_list}!", "Example fragment", {:user_list => [[user1, user2, user3], :name]}}
475
- #
476
- # first element is an array, the rest of the elements are similar to the
477
- # regular tokens lambda, symbol, string, with parameters that follow
478
- #
479
- # if you want to pass options, then make the second parameter an array as well
480
- #
481
- # tr("{user_list} joined Geni", "",
482
- # {:user_list => [[user1, user2, user3],
483
- # [:name], # this can be any of the value methods
484
- # { :expandable => true,
485
- # :to_sentence => true,
486
- # :limit => 4,
487
- # :separator => ',',
488
- # :translate_items => false,
489
- # :minimizable => true
490
- # }
491
- # ]
492
- # ]})
493
- #
494
- ##############################################################################
495
- </pre>
496
- </div>
497
-
498
- As you can see from the definition above, if you make the second parameter of the tr function an array as well, you can provide a third parameter
499
- that would indicate how to display the array values. Let's try the following example:
500
-
501
- <div class="snippet">
502
- users = 1.upto(10).collect{|i| User.new(:name => "User #{i}", :gender => 'male')}<br><br>
503
- tr("{users} joined the site!", "Newsfeed story header", :users => [users, :name])
504
- </div>
505
-
506
- <br>
507
- The above example uses the second parameter as method symbol, which indicates that default display params will be used, resulting in:
508
- <div class="snippet2">
509
- <% users = 1.upto(10).collect{|i| Tr8n::Translator.new(:name => "User #{i}", :gender => 'male')} %>
510
- <%= tr("{users} joined the site!", "Newsfeed story header", :users => [users, :name]) %>
511
- </div>
512
-
513
- Notice that the expandable flag was set to true, limit was set to 4, etc... resulting in display of 4 names with an expandable link to display the rest of the names
514
-
515
- Lets try changing the parameters to display limit 3 and try again:
516
-
517
- <div class="snippet">
518
- users = 11.upto(15).collect{|i| User.new(:name => "User #{i}", :gender => 'male')}<br><br>
519
- tr("{users} joined the site!", "Newsfeed story header", :users => [users, [:name], {:limit => 3}])
520
- </div>
521
-
522
- <div class="snippet2">
523
- <% users = 11.upto(15).collect{|i| Tr8n::Translator.new(:name => "User #{i}", :gender => 'male')} %>
524
- <%= tr("{users} joined the site!", "Newsfeed story header", :users => [users, [:name], {:limit => 3}]) %>
525
- </div>
526
-
527
- Notice that the above two examples use the same translation key. You got the idea! You can try changinging other parameters and see what happens.
528
- </p>
529
-
530
-
531
- <a name="date_rules">&nbsp;</a>
532
- <h3>Date Rules</h3>
533
- <p>
534
- Date Rule is a very simple rule. It is used to evaluate the default as well as the translated phrases using the date object. For instance:
535
-
536
- <div class="snippet">
537
- tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!", "Birthday notification", :user => current_user, :birth_date => Date.today)
538
- </div>
539
-
540
- This looks a little cryptic at first because it actually compresses three sentences and a bunch of translations into a simple phrase. Let's take a closer look:
541
-
542
- <div style="padding-left:20px; padding-bottom:10px;">
543
- <ul style="list-style-type:square">
544
- <li><strong>token_suffixes</strong> indicates the set of token names that have numerical values and can be translated using numeric context rule</li>
545
- <li><strong>object_method</strong> indicates the method that must be applied on the token object in order to get its numerical value</li>
546
- </ul>
547
- </div>
548
-
549
- Let's try the following variations:
550
-
551
- <div class="snippet">
552
- tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!",
553
- "Birthday notification", :user => current_user, :birth_date => [Date.today - 1.day, :strftime, "%D"]) <br><br>
554
-
555
- tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!",
556
- "Birthday notification", :user => current_user, :birth_date => [Date.today, :strftime, "%D"]) <br><br>
557
-
558
- tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!",
559
- "Birthday notification", :user => current_user, :birth_date => [Date.today + 1.day, :strftime, "%D"]) <br><br>
560
- </div>
561
-
562
- Change your language, enable inline translations and try translating the following sentence:
563
- <div class="snippet2">
564
- <%= tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!", "Birthday notification", :user => Tr8n::Config.current_user, :birth_date => [Date.today - 1.day, :strftime, "%D"]) %>
565
- <br><br>
566
- <%= tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!", "Birthday notification", :user => Tr8n::Config.current_user, :birth_date => [Date.today, :strftime, "%D"]) %>
567
- <br><br>
568
- <%= tr("{user} {birth_date| celebrated, celebrates, will celebrate} {user|his,her} birthday on {birth_date}!", "Birthday notification", :user => Tr8n::Config.current_user, :birth_date => [Date.today + 1.day, :strftime, "%D"]) %>
569
- </div>
570
-
571
- All those variations have only created a single translation key in the default language. But transling them into other languages is a whole different story.
572
- <br><br>
573
- <%=image_tag("/tr8n/images/examples/date_rules_1.png", :style =>"vertical-align:top; padding-right:15px;")%>
574
- <%=image_tag("/tr8n/images/examples/date_rules_2.png", :style =>"vertical-align:top")%><br><br>
575
-
576
- Translating the above sentece into Russian will require setting up a dependency on the {user} token, as well as {date} token. Both of the tokens have 3 rules
577
- and will result in the total of 9 translations.<br><br>
578
- <%=image_tag("/tr8n/images/examples/date_rules_3.png", :style => "width:800px; border:1px solid #ccc;")%><br><br>
579
-
580
- <br>
581
- <strong>Date Rule Definition</strong><br><br>
582
- <div style="padding-left:20px; padding-bottom:10px;">
583
- <ul style="list-style-type:square">
584
- <li>A rule consists of 2 parts: operator and timeframe.</li>
585
- <li>The operator options are: "is in the", "is not in the"</li>
586
- <li>The timeframe options are: "past", "present", "future"</li>
587
- </ul>
588
- </div>
589
-
590
- <br>
591
- <strong>Date Rule Configuration</strong><br><br>
592
- <div class="snippet" style="font-size:11px;">
593
- <pre>
594
- rules_engine:
595
- ...
596
- <strong>date_rule:
597
- token_suffixes: [date]
598
- object_method: to_date
599
- </strong>
600
- ...
601
- </pre>
602
- </div>
603
-
604
- <br>
605
- <strong>Date Rule</strong> is implemented by the <strong>Tr8n::DateRule</strong> class and uses the <strong>date_rule</strong> section of the rules_engine configuration.
606
- <br><br>
607
- <div style="padding-left:20px; padding-bottom:10px;">
608
- <ul style="list-style-type:square">
609
- <li><strong>token_suffixes</strong> indicates the set of token names that have date values and can be translated using date context rule</li>
610
- <li><strong>object_method</strong> indicates the method that must be applied on the token object in order to get its date value</li>
611
- </ul>
612
- </div>
613
-
614
- </p>
615
-
616
- <a name="value_rules">&nbsp;</a>
617
- <h3>Value Rules</h3>
618
- <p>
619
- Value rules are used for contextual translations of phrases where other parts of the phrase depends on the value of the token. Those rules are usually used in
620
- combintation with the Language Case Rules, which will be described in the later sections.
621
-
622
- <br><br>
623
- <strong>Value Rule Definition</strong><br><br>
624
- <div style="padding-left:20px; padding-bottom:10px;">
625
- <ul style="list-style-type:square">
626
- <li>A rule consists of 2 parts: operator and value.</li>
627
- <li>The operator options are: "is", "is not", "starts with", "does not start with", "ends in", "does not end in"</li>
628
- <li>The value can be anything provided by the language manager</li>
629
- </ul>
630
- </div>
631
-
632
- <br>
633
- <strong>Value Rule Configuration</strong><br><br>
634
- <div class="snippet" style="font-size:11px;">
635
- <pre>
636
- rules_engine:
637
- ...
638
- <strong>value_rule:
639
- token_suffixes: *
640
- object_method: to_s
641
- </strong>
642
- ...
643
- </pre>
644
- </div>
645
-
646
- <br>
647
- <strong>Value Rule</strong> is implemented by the <strong>Tr8n::ValueRule</strong> class and uses the <strong>value_rule</strong> section of the rules_engine configuration.
648
- <br><br>
649
- <div style="padding-left:20px; padding-bottom:10px;">
650
- <ul style="list-style-type:square">
651
- <li><strong>token_suffixes</strong> indicates that it can be applied to any token</li>
652
- <li><strong>object_method</strong> indicates the method that must be applied on the token object in order to get its date value</li>
653
- </ul>
654
- </div>
655
-
656
- </p>
657
-
658
- <a name="language_cases">&nbsp;</a>
659
- <h2>Language Case Rules</h2>
660
- <p>
661
- A language case is an inflection or use of a noun (or pronoun) to show its relation to other words in the sentence. In some languages, like Russian, the form of a token {actor} will changed based on where and how the token is used in a sentence. For instance, in '{target} received a gift from {actor}', {actor} token will be in the genitive form of the language.
662
-
663
- <br><br>
664
- Work in progress, please be patient...
665
- </p>
666
-
667
- </div>
668
- <% end %>