r18n-rails 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +383 -0
  3. data/README.md +73 -59
  4. data/lib/r18n-rails.rb +32 -20
  5. data/lib/r18n-rails/filters.rb +2 -2
  6. data/lib/r18n-rails/helpers.rb +5 -6
  7. data/lib/r18n-rails/{controller.rb → hooks_helper.rb} +39 -15
  8. data/lib/r18n-rails/translated.rb +5 -4
  9. data/lib/r18n-rails/version.rb +7 -0
  10. metadata +217 -69
  11. data/.rspec +0 -1
  12. data/Rakefile +0 -15
  13. data/r18n-rails.gemspec +0 -32
  14. data/spec/app/app/controllers/application_controller.rb +0 -5
  15. data/spec/app/app/controllers/test_controller.rb +0 -50
  16. data/spec/app/app/i18n/en.yml +0 -6
  17. data/spec/app/app/i18n/filters.rb +0 -5
  18. data/spec/app/app/i18n/ru.yml +0 -2
  19. data/spec/app/app/mailers/test_mailer.rb +0 -9
  20. data/spec/app/app/models/post.rb +0 -6
  21. data/spec/app/app/views/test/format.html.erb +0 -1
  22. data/spec/app/app/views/test/helpers.html.erb +0 -4
  23. data/spec/app/app/views/test/safe.html.erb +0 -1
  24. data/spec/app/app/views/test_mailer/test.text.erb +0 -3
  25. data/spec/app/config.ru +0 -6
  26. data/spec/app/config/application.rb +0 -28
  27. data/spec/app/config/boot.rb +0 -6
  28. data/spec/app/config/environment.rb +0 -7
  29. data/spec/app/config/environments/test.rb +0 -14
  30. data/spec/app/config/initializers/r18n.rb +0 -4
  31. data/spec/app/config/initializers/secret_token.rb +0 -3
  32. data/spec/app/config/locales/en.yml +0 -7
  33. data/spec/app/config/locales/ru.yml +0 -20
  34. data/spec/app/config/routes.rb +0 -15
  35. data/spec/app/db/migrate/20091218123631_create_posts.rb +0 -14
  36. data/spec/app/db/schema.rb +0 -22
  37. data/spec/rails_spec.rb +0 -183
  38. data/spec/spec_helper.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bffe7c01c01781a342b1dd447c2bf438a307cc5a5c8113e7520af8d4de706787
4
- data.tar.gz: e261678db0929a8ac27f39e6b91e7f954bde7c363a48e8fee5438d4b6060876e
3
+ metadata.gz: 30eb70ac87022feb93c7b8ba631537c3f29efeb885613b815ac1c95f3f0ae7cd
4
+ data.tar.gz: 72ce692a04c12063d34693b42aeb00d910984a3f81206ad2f6531fbc272de87b
5
5
  SHA512:
6
- metadata.gz: e100aec03ba69b888f04bf1bca45e8cd7d2e96b284d29478036e624e559bf9c663c0b1eeedec6dab8fd19fda2de3b45b7ced98d3b695972a2ed8613dbcab2802
7
- data.tar.gz: 42f6d7bba9aad7561e312417f08c971840500587e2ab75e0a5299d786a89948d7f063891cd8cf523d37afe67040eaaa205ebc01a1c16ba22f7ac7f79bd1b55f9
6
+ metadata.gz: 9c00c4b7d5ffc4252a1a42b2c7ae61ce5bcc7fb8d8aee44fe07fd6098486ed1e4b5634775508c3b5503f0e199e68282082993c480b9c553e0da8df571eef45f7
7
+ data.tar.gz: 1502309e53317b831ce862c6db31bbbe79585314e157a3990abf85748d457f582e5312142817d5f35c85017f1390bc4cb58b1b50149e1ea4590c8028ebd4325d
data/ChangeLog.md ADDED
@@ -0,0 +1,383 @@
1
+ # Change Log
2
+
3
+ ## Unreleased
4
+
5
+ ## 5.0.0 (Warszawa) (2021-03-04)
6
+
7
+ * Take out `r18n-rails` gem from mono-repository.
8
+ * Drop Ruby 2.4 support.
9
+ * Support Ruby 3.
10
+ * Avoid Ruby 4 in gem specs.
11
+ * Add metadata to gem specs.
12
+ * Add Alexander Popov as a gem author.
13
+ * Replace `rake` with `toys`.
14
+ * Add Codecov and SimpleCov.
15
+ * Update RuboCop, its configuration, and resolve new offenses.
16
+ * Add badges into README.
17
+
18
+ All core changes now check in [the `r18n-core` repository](https://github.com/r18n/r18n-core)
19
+ and [the `r18n-rails-api` repository](https://github.com/r18n/r18n-rails-api).
20
+
21
+ ## 4.0.0 (Santiago)
22
+
23
+ * Drop Ruby 2.3 support (by Alexander Popov).
24
+ * Drop `R18n::Utils.hash_map` (by Alexander Popov).
25
+ * Add Ruby 2.6 and 2.7 for CI (by Alexander Popov).
26
+ * Allow to add custom (per-project) locales (by Alexander Popov).
27
+ * Add block for `R18n.change` (change affects only code inside block)
28
+ (by Alexander Popov).
29
+ * Add `language` and `region` readers for `Locale` (by Alexander Popov).
30
+ * Allow upcased region in translation file names (like `en-US.yml`)
31
+ (by Alexander Popov).
32
+ * Load `base` translations from parent locale (by Alexander Popov).
33
+ * Downcase locales with regions for `Translated`, like `name_en_us`
34
+ instead of `name_en-US` (by Alexander Popov).
35
+ * Add Spanish Chile (`es-CL`) (by Juan Gil Miqueo).
36
+ * Add `:with_seconds` option for Time formatting (by Alexander Popov).
37
+ * Replace custom `gsub` in `R18n::Utils.escape_html` with `CGI.escapeHTML`
38
+ (by Alexander Popov).
39
+ * Improve Indonesian translation (by Mohammad Satrio).
40
+ * Improve documentation (by Alexander Popov).
41
+ * Fix issue with wildcard in `Accept-Language` header (by Alexander Popov).
42
+
43
+ ## 3.2.0 (Kawasaki)
44
+ * Support `*.yaml` files (by Alexander Popov).
45
+ * Locate processed `code` in `UnsupportedLocale`, like in `Locale` (by Alexander Popov).
46
+ * Fix `TranslatedString#to_ary`, don't return `Untranslated` (by Alexander Popov).
47
+ * Add Welsh language (`cy`) (by Mei Gwilym).
48
+ * Add support for custom classes localizing (`R18n.l`) (by Alexander Popov).
49
+ * Replace blank-padded day in date with no-padded (by Alexander Popov).
50
+ * Fix `TranslatedString#to_hash` (by Christian Höppner and Alexander Popov).
51
+
52
+ ## 3.1.2 (i)
53
+ * Call `Translation#itself` as translation key instead of `Kernel#itself` implementation (by Alexander Popov).
54
+
55
+ ## 3.1.1 (У)
56
+ * Fix errors and warnings from `gem build`
57
+
58
+ ## 3.1 (Одинцово)
59
+ * Move `named_variables` filter from `r18n-rails-api` to `r18n-core` (by Alexander Popov).
60
+ * Add possibility for `R18n::Locale` to define custom formatters (by Alexander Popov).
61
+ * Fix `R18n.set` for `r18n-desktop` (by Alexander Popov).
62
+
63
+ ## 3.0.5 (ب)
64
+ * Fix Farsi locale name (by @iriman).
65
+
66
+ ## 3.0.4 (𐤀)
67
+ * Fix `Translated` compatibility with `Hash` (by Alexander Popov).
68
+
69
+ ## 3.0.3 (〥)
70
+ * Fix missed filters in `Untranslted` initialization (by Alexander Popov).
71
+
72
+ ## 3.0.2 (Ё)
73
+ * Fix `Untranslted.to_s` (by Patrik Rak).
74
+
75
+ ## 3.0.1 (Brooklyn)
76
+ * Fix `no` locale deprecation warning.
77
+
78
+ ## 3.0 (New York)
79
+ * Deprecate `no` locale, use `nb` instead (by Alexander Popov).
80
+ * Remove unsafe `!!proc` filter.
81
+ * Reduce `eval` calls (by Alexander Popov).
82
+
83
+ ## 2.2 (La Habana)
84
+ * Change date format in `en` locale to `YYYY-MM-DD` (by Alexander Popov).
85
+ * Add `TranslatedString#as_json` for ActiveSupport compatibility (by Tim Craft).
86
+ * Fix `TranslatedString#html_safe?` behavior (by Tim Craft).
87
+ * Fix unsupported `LANG` environment (by Chris Poirier).
88
+ * Fix `Locale#localize` method for `DateTime` objects (by Alexander Popov).
89
+
90
+ ## 2.1.8 (Ѣ)
91
+ * Fix `true` and `false` keys support (by Alexander Popov).
92
+
93
+ ## 2.1.7 (Sewe)
94
+ * Add Afrikaans locale (by Llewellyn van der Merwe).
95
+
96
+ ## 2.1.6 (Berlin)
97
+ * Better `TranslatedString` → `String` converting (by Patrik Rak).
98
+ * Add Ruby on Rails 5 support.
99
+
100
+ ## 2.1.5 (මාතර)
101
+ * Fix Ruby 2.4 support (by Alexander Popov)
102
+
103
+ ## 2.1.4 (Bakı)
104
+ * Add Azerbaijani locale (by Adil Aliyev).
105
+
106
+ ## 2.1.3 (Seoul)
107
+ * Add Korean locale (by Patrick Cheng).
108
+
109
+ ## 2.1.2 (Wien)
110
+ * Fix Ruby 2.3 support.
111
+
112
+ ## 2.1.1 (Barcelona)
113
+ * Better sanity check for Accept-Language header (by Viktors Rotanovs).
114
+
115
+ ## 2.1 (Một)
116
+ * Add Vietnamese locale (by Nguyễn Văn Được).
117
+ * Add Persian locale.
118
+ * Allow to change date/time order in locales.
119
+ * Fix pluralization in locales without plural forms.
120
+ * Fix Mongolian base translations.
121
+
122
+ ## 2.0.4 (Ikkuna)
123
+ * Fix Windows support (by janahanEDH).
124
+
125
+ ## 2.0.3 (Hévíz)
126
+ * Fix Thai locale (by Kasima Tharnpipitchai).
127
+
128
+ ## 2.0.2 (Budapest)
129
+ * Fix array support in translations.
130
+ * Fix Rails support for dialect locales.
131
+
132
+ ## 2.0.1 (Amsterdam)
133
+ * Fix Dutch locale.
134
+
135
+ ## 2.0.0 (Москва)
136
+ * Remove Ruby 1.8 and 1.9 support.
137
+ * Add JRuby 9000 support.
138
+
139
+ ### 1.1.11 (São Paulo)
140
+ * Allow to set Proc as `default` option in Rails I18n back-end.
141
+
142
+ ### 1.1.10 (十)
143
+ * Fix Esperanto locale by Larry Gilbert.
144
+ * Fix Chinese locale (by 刘当一).
145
+
146
+ ### 1.1.9 (Не знайдено)
147
+ * Fix Rails 4.0.4 support. Prevent loop on `enforce_available_locales`.
148
+
149
+ ### 1.1.8 (Osam)
150
+ * Add Croatian locale (by Dino Kovač).
151
+ * Add Serbian latin locale (by Dino Kovač).
152
+
153
+ ### 1.1.7 (Tujuh)
154
+ * Return `nil` on untranslated in models with Translated.
155
+ * Add `transliterate` method to I18n back-end.
156
+ * Add Indonesian locale (by Guntur Akhmad).
157
+
158
+ ### 1.1.6 (Vitebsk)
159
+ * Return `TranslatedString` after global String filters.
160
+ * Fix path in global String filters.
161
+
162
+ ### 1.1.5 (Hilo)
163
+ * Fix Sinatra plugin under multi-threaded web-server (by Viktors Rotanovs).
164
+ * Fix `BigDecimal` localizing (by François Beausoleil).
165
+ * Add American American Spanish locale (by renemarcelo).
166
+
167
+ ### 1.1.4 (Bokmål)
168
+ * Add Norwegian `no` locale as gateway to Bokmål or Nynorsk.
169
+ * Fix Norwegian Bokmål locale code.
170
+ * Fix Hungarian time format (Kővágó Zoltán).
171
+
172
+ ### 1.1.3 (Saint Petersburg)
173
+ * Fix memory leak from cache key mismatch in Rails plugin (by silentshade).
174
+
175
+ ### 1.1.2 (Marshal)
176
+ * Fix translation and untranslated marshalizing (by silentshade).
177
+ * Allow to compare untranslated strings.
178
+ * Fix untranslated strings output in tests.
179
+
180
+ ### 1.1.1 (Dunhuang)
181
+ * Don't change YAML parser in Ruby 1.9.
182
+ * Allow to change locale by argument in R18n Rails back-end.
183
+ * Set also Rails I18n locale in Rails auto-detect filter.
184
+ * Fix caching with custom filters (by Anton Onyshchenko).
185
+ * Fix translation variables with `%1` text inside (by Taras Kunch).
186
+ * Fix Latvian locale (by Aleksandrs Ļedovskis).
187
+
188
+ ### 1.1.0 (Leipzig)
189
+ * A lot of fixes in Rails I18n compatibility (thanks for Stephan Schubert).
190
+ * Return `Untranslted`, when user try to call another translation key on
191
+ already translated string.
192
+ * Add `Translation#to_hash` to get raw translation.
193
+ * Add `Translation#inspect` to easy debug.
194
+ * Return translation, when pluralization filter did not get count.
195
+ * Set R18n back-end on Rails plugin init, to use it in console.
196
+ * Allow to use Integer in translation keys.
197
+
198
+ ### 1.0.1 (Phuket Town)
199
+ * Fix translation reloading in Rails and Sinatra.
200
+ * Use global R18n settings for Sinatra extension.
201
+ * Allow to override desktop auto-detect by LANG environment on all platforms.
202
+ * Add support for JRuby in 1.9 mode.
203
+ * Rename `R18n.reset` to `R18n.reset!` and add `R18n.clear_cache!`.
204
+ * Fix Sinatra with loaded ActiveSupport.
205
+ * Add Mongolian locale (by Elias Klughammer).
206
+
207
+ ### 1.0.0 (Bangkok)
208
+ * Add `R18n.default_places`.
209
+ * Rails `SafeBuffer` support.
210
+ * Allow in Rails app to put filters to `app/i18n` reload them in development.
211
+ * Move `R18n::I18n.available_locales` to `R18n.available_locales`.
212
+ * Rename `_keys` to `translation_keys`.
213
+ * Use Kramdown instead of Maruku for Markdown.
214
+ * Allow to use R18n for Rails without mailer.
215
+ * Allow to overwrite I18n object for models.
216
+ * Autoload R18n::Translated.
217
+ * Set default locale to R18n on Rails start to easy use in Rails console.
218
+ * Use env language in Rails console.
219
+ * Mark untranslated part as red in Rails console.
220
+ * Allow to temporary change locale by `R18n.change`.
221
+ * Add `R18n.locale` shortcut.
222
+ * Allow return from setter block locale code, instead of I18n object.
223
+ * Allow to set custom filters for I18n object.
224
+ * Add Galician locale (by Eduard Giménez).
225
+ * Add Traditional Chinese and Simplified Chinese (by Francis Chong).
226
+ * Fix Norsk locale (by Peter Haza).
227
+
228
+ ### 0.4.14 (üç)
229
+ * Fix support for Ruby 1.9.3.
230
+ * Added Turkish locale (by Ahmet Özkaya).
231
+ * Fix Swedish locale (by Pär Wieslander).
232
+
233
+ ### 0.4.13 (Sti)
234
+ * Fix `Pathname` to `String` error in `r18n-desktop`.
235
+ * Add Norwegian locale (by Oddmund Strømme).
236
+
237
+ ### 0.4.12 (Шлях)
238
+ * Fix `Pathname` to `String` conversion error.
239
+ * Fix model translation for non-ActiveRecord (by Szymon Przybył).
240
+ * Add Ukrainian locale (by Ярослав Руденок).
241
+
242
+ ### 0.4.11 (Nancy)
243
+ * Support for Sinatra 1.3.
244
+ * Fix JRuby support by Paul Walker.
245
+ * Add R18n helpers to Rails mailer by Alexey Medvedev.
246
+
247
+ ### 0.4.10 (Kvantum)
248
+ * Add R18n.set(locales, places), R18n.t and R18n.l shortcuts.
249
+ * Convert float to number on pluralization.
250
+ * Fix loading empty translation file.
251
+ * Add Portuguese locale.
252
+ * Add Dutch locale (by Sander Heilbron).
253
+ * Add Swedish locale (by Magnus Hörberg).
254
+
255
+ ### 0.4.9 (Kazan)
256
+ * Add support for Psych YAML parser (thanks for Ravil Bayramgalin).
257
+ * Fix ActiveRecord support in Translated.
258
+ * Fix Translated to return non-string values.
259
+ * Fix human time localization.
260
+ * Add Bulgarian locale (by Mitko Kostov).
261
+ * Add Australian English locale (by Dave Sag).
262
+
263
+ ### 0.4.8 (En ni to)
264
+ * Fix support for Ruby 1.9.2.
265
+ * Fix caching issue (by Viktors Rotanovs).
266
+ * Add Danish locale (by Hans Czajkowski Jørgensen)
267
+ * Fix Italian locale (by Viktors Rotanovs).
268
+ * Move untranslated filters with html highlight to `r18n-core`.
269
+
270
+ ### 0.4.7.1 (Kyū)
271
+ * Fix Japanese locale in Ruby 1.9.1.
272
+
273
+ ### 0.4.7 (Mado)
274
+ * Fix auto-detect locale in Windows and Ruby 1.9.1 (by Marvin Gülker).
275
+ * Fix auto-detect locale in JRuby (by Kővágó, Zoltán).
276
+ * Fix human time format on 60 minutes.
277
+ * Add Hungarian locale (by Kővágó, Zoltán).
278
+ * Add Japanese locale (by hryk).
279
+ * Fix Polish locale (by Piotr Szotkowski).
280
+
281
+ ### 0.4.6 (Trinity)
282
+ * Add support for new interpolation syntax in Rails 3.
283
+ * Add Catalian locale (by Jordi Romero).
284
+ * Add Finish locale (by Laura Guillén).
285
+ * Add British locale (by JP Hastings-Spital).
286
+ * Add Latvian locale (by Iļja Ketris).
287
+ * Fix Spanish (by Jordi Romero), German, French, Esperanto (by Iļja Ketris) and
288
+ Polish locales.
289
+ * Fix documentation (by Iļja Ketris and felix).
290
+ * Remove RubyGems from plugins requires.
291
+
292
+ ### 0.4.5 (Annual)
293
+ * Filters for several types.
294
+ * Global HTML escaping run before Markdown and Textile formatting.
295
+ * Fix active filters after passive filters.
296
+ * Fix human time formatting for dates with same month days.
297
+
298
+ ### 0.4.4 (Frank)
299
+ * Use before filter to lazy set I18n object in Sinatra extension.
300
+ * Set I18n object to thread (by Simon Hafner).
301
+ * Add to l Rails helper R18n syntax.
302
+ * Add common helpers.
303
+ * Clear cache in `R18n.reset`.
304
+ * Clean up code and fix bug (by Akzhan Abdulin).
305
+ * Add Thai locale (by Felix Hanley).
306
+
307
+ ### 0.4.3 (Flange)
308
+ * Add R18n style methods to Rails controllers.
309
+ * Fix for non-string translations in Rails I18n.
310
+ * Use default locale from Rails I18n config.
311
+ * Load translations recursively.
312
+ * Add Slovak locale (by Ahmed Al Hafoudh)
313
+
314
+ ### 0.4.2 (EMS)
315
+ * Fixes for Ruby 1.8.6 (by Akzhan Abdulin).
316
+ * Add method to get translation keys.
317
+
318
+ ### 0.4.1 (Lazy Boole)
319
+ * Add passive filters.
320
+ * Receive filter position as option `Hash`.
321
+ * Fix base translations (by Pavel Kunc).
322
+
323
+ ### 0.4 (D-Day)
324
+ * Rails I18n compatibility.
325
+ * Rewrite a lot of core code to fast and cleanup version.
326
+ * Custom translation loaders.
327
+ * Add reload! method to I18n.
328
+ * Add t and l helpers to Sinatra and desktop plugins.
329
+ * Syntax sugar for default values.
330
+ * Named variables.
331
+ * New locale API.
332
+ * Change API for extension translations.
333
+
334
+ ### 0.3.2 (Pidgin)
335
+ * Print path of untranslated string by filters.
336
+ * Add Italian locale (by Guido De Rosa).
337
+ * Fix Polish locale (by Adrian Pacała).
338
+ * Fix American English locale (by Max Aller).
339
+
340
+ ### 0.3.1 (Yield)
341
+ * Add Chinese locale (by Ilia Zayats).
342
+ * Add Spanish locale (by Andre O Moura).
343
+ * Add Brazilian Portuguese locale (by Andre O Moura).
344
+ * Remove RubyGems requires.
345
+
346
+ ### 0.3 (Vladivostok)
347
+ * `Translated` mixin to I18n support to model or any other class.
348
+ * New cool time formatters.
349
+ * Filters for translations.
350
+ * Add filters to escape HTML, Markdown and Textile syntax.
351
+ * Pluralization and variables is now filters and can be replaced.
352
+ * I18n#locales now contain all detected locales, used to load translations,
353
+ instead of just received from user.
354
+ * Bug-fix in locale code case.
355
+ * Add Czech locale (by Josef Pospíšil).
356
+
357
+ ### 0.2.3 (Shanghai eclipse)
358
+ * R18n will return path string if translation isn't exists.
359
+ * Add `UnsupportedLocale` class for locale without information file.
360
+ * Load absent locale information from default locale.
361
+ * Add Polish locale (by Tymon Tobolski).
362
+
363
+ ### 0.2.2 (Clone Wars)
364
+ * Localize numbers in pluralization.
365
+ * Bug-fix in translation variables.
366
+
367
+ ### 0.2.1 (Neun)
368
+ * Ruby 1.9 compatibility.
369
+ * Add German locale (by Benjamin Meichsner).
370
+
371
+ ### 0.2 (Freedom of Language)
372
+ * Locale class can be extended for special language (for example, Indian locale
373
+ may has another digits grouping).
374
+ * Load translations from several dirs.
375
+ * Add French locale.
376
+ * Add Kazakh locale.
377
+
378
+ ### 0.1.1 (Saluto)
379
+ * Loading I18n object without translations.
380
+ * Add output for standalone month name.
381
+ * Don't call procedures from translations if it isn't secure.
382
+ * Add Esperanto locale.
383
+ * English locale now contain UK date standards.
data/README.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # R18n for Rails
2
2
 
3
- R18n-rails is a gem to add out-of-box R18n support to Rails I18n.
3
+ [![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/r18n/r18n-rails?style=flat-square)](https://cirrus-ci.com/github/r18n/r18n-rails)
4
+ [![Codecov branch](https://img.shields.io/codecov/c/github/r18n/r18n-rails/master.svg?style=flat-square)](https://codecov.io/gh/r18n/r18n-rails)
5
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/r18n/r18n-rails.svg?style=flat-square)](https://codeclimate.com/github/r18n/r18n-rails)
6
+ [![Depfu](https://img.shields.io/depfu/r18n/r18n-rails?style=flat-square)](https://depfu.com/repos/github/r18n/r18n-rails)
7
+ [![License](https://img.shields.io/github/license/r18n/r18n-rails.svg?style=flat-square)](LICENSE)
8
+ [![Gem](https://img.shields.io/gem/v/r18n-rails.svg?style=flat-square)](https://rubygems.org/gems/r18n-rails)
4
9
 
5
- It is a wrapper for R18n Rails API and R18n core libraries. See R18n core
6
- documentation for more information.
10
+ R18n-rails is a gem to add out-of-box [R18n](https://github.com/r18n/r18n) support to Rails I18n.
11
+
12
+ It is a wrapper for [R18n Rails API](https://github.com/r18n/r18n-rails-api)
13
+ and [R18n core](https://github.com/r18n/r18n-core) libraries.
14
+ See [R18n core documentation](https://github.com/r18n/r18n-core/blob/master/README.md)
15
+ for more information.
7
16
 
8
17
  ## Features
9
18
 
@@ -20,35 +29,36 @@ See full features in [main README](https://github.com/r18n/r18n/blob/master/READ
20
29
 
21
30
  ## How To
22
31
 
23
- 1. Add `r18n-rails` gem to your `Gemfile`:
32
+ 1. Add `r18n-rails` gem to your `Gemfile`:
24
33
 
25
34
  ```
26
35
  gem 'r18n-rails'
27
36
  ```
28
- Now R18n will auto-detect user locales.
29
- 2. Define your way to set locale manually. R18n will find it in
30
- `params[:locale]` or `session[:locale]`. Best way is a put optional
31
- locale prefix to URLs:
37
+ Now R18n will auto-detect user locales.
38
+
39
+ 2. Define your way to set locale manually. R18n will find it in
40
+ `params[:locale]` or `session[:locale]`. Best way is a put optional
41
+ locale prefix to URLs:
32
42
 
33
- ```ruby
43
+ ```ruby
34
44
  match ':controller/:action'
35
45
  match ':locale/:controller/:action'
36
- ```
46
+ ```
37
47
 
38
- 3. Print available translations, to choose from them manually (and to help
39
- search engines):
48
+ 3. Print available translations, to choose from them manually (and to help
49
+ search engines):
40
50
 
41
- ```haml
42
- %ul
43
- - r18n.available_locales.each do |locale|
44
- %li
45
- %a( href="/#{locale.code}/" )= locale.title
46
- ```
51
+ ```haml
52
+ %ul
53
+ - r18n.available_locales.each do |locale|
54
+ %li
55
+ %a( href="/#{locale.code}/" )= locale.title
56
+ ```
47
57
 
48
- 4. Translations in I18n format are stored in
49
- `config/locales/%{locale}.yml`:
58
+ 4. Translations in I18n format are stored in
59
+ `config/locales/%{locale}.yml`:
50
60
 
51
- ```yaml
61
+ ```yaml
52
62
  en:
53
63
  user:
54
64
  name: "User name is %{name}"
@@ -56,93 +66,97 @@ See full features in [main README](https://github.com/r18n/r18n/blob/master/READ
56
66
  zero: "No users"
57
67
  one: "One user"
58
68
  many: "%{count} users"
59
- ```
60
- Translations in R18n format go to `app/i18n/%{locale}.yml`:
69
+ ```
70
+ Translations in R18n format go to `app/i18n/%{locale}.yml`:
61
71
 
62
- ```yaml
72
+ ```yaml
63
73
  user:
64
74
  name: User name is %1
65
75
  count: !!pl
66
76
  0: No users
67
77
  1: 1 user
68
78
  n: '%1 users'
69
- ```
79
+ ```
70
80
 
71
- 5. Use translated messages in views. You can use Rails I18n syntax:
81
+ 5. Use translated messages in views. You can use Rails I18n syntax:
72
82
 
73
- ```ruby
83
+ ```ruby
74
84
  t 'user.name', name: 'John'
75
85
  t 'user.count', count: 5
76
- ```
77
- or R18n syntax:
86
+ ```
78
87
 
79
- ```ruby
88
+ or R18n syntax:
89
+
90
+ ```ruby
80
91
  t.user.name(name: 'John') # for Rails I18n named variables
81
92
  t.user.name('John') # for R18n variables
82
93
  t.user.count(5)
83
- ```
94
+ ```
84
95
 
85
- 6. Print dates and numbers in user's tradition:
96
+ 6. Print dates and numbers in user's tradition:
86
97
 
87
- ```ruby
98
+ ```ruby
88
99
  l Date.today, :standard #=> "2009-12-20"
89
100
  l Time.now, :full #=> "20th of December, 2009 12:00"
90
101
  l 1234.5 #=> "1,234.5"
91
- ```
102
+ ```
92
103
 
93
- 7. Translate models. You can use `R18n::Translated` mixin for any Ruby class,
94
- not only for ActiveRecord models
104
+ 7. Translate models. You can use `R18n::Translated` mixin for any Ruby class,
105
+ not only for ActiveRecord models
95
106
 
96
- 1. Add to migration columns for each of the supported locales, named as
97
- `%{name}_%{locale}`:
107
+ 1. Add to migration columns for each of the supported locales, named as
108
+ `%{name}_%{locale}`:
98
109
 
99
- ```ruby
110
+ ```ruby
100
111
  t.string :title_en
101
112
  t.string :title_ru
102
113
 
103
114
  t.string :text_en
104
115
  t.string :text_ru
105
- ```
116
+ ```
106
117
 
107
- 2. Add `R18n::Translated` mixin to model:
118
+ 2. Add `R18n::Translated` mixin to model:
108
119
 
109
120
  ```ruby
110
- class Post < ActiveRecord::Base
121
+ class Post < ActiveRecord::Base
111
122
  include R18n::Translated
112
123
  ```
113
124
 
114
- 3. Call `translations` method in model with all columns to be translated:
125
+ 3. Call `translations` method in model with all columns to be translated:
115
126
 
116
127
  ```ruby
117
- translations :title, :text
128
+ translations :title, :text
118
129
  ```
119
- Now model will have virtual methods `title`, `text`, `title=`
120
- and `text=`, which will call `title_ru` or `title_en` and etc based
121
- on current user locales.
130
+ Now model will have virtual methods `title`, `text`, `title=`
131
+ and `text=`, which will call `title_ru` or `title_en` and etc based
132
+ on current user locales.
122
133
 
123
- 8. Download translations for Rails system messages (validation, etc) from
124
- [svenfuchs/rails-i18n](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale)
125
- and put them to `config/locales/` (because them use Rails I18n format).
126
- 9. Add your own translations filters to `app/i18n/filters.rb`:
134
+ 8. Download translations for Rails system messages (validation, etc) from
135
+ [svenfuchs/rails-i18n](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale)
136
+ and put them to `config/locales/` (because them use Rails I18n format).
127
137
 
128
- ```ruby
138
+ 9. Add your own translations filters to `app/i18n/filters.rb`:
139
+
140
+ ```ruby
129
141
  R18n::Filters.add('gender') do |translation, config, user|
130
142
  translation[user.gender]
131
143
  end
132
- ```
133
- And use in translations:
144
+ ```
134
145
 
135
- ```yaml
146
+ And use in translations:
147
+
148
+ ```yaml
136
149
  log:
137
150
  signup: !!gender
138
151
  male: Он зарегистрировался
139
152
  female: Она зарегистрировалась
140
- ```
141
- and application:
153
+ ```
142
154
 
143
- ```ruby
155
+ and application:
156
+
157
+ ```ruby
144
158
  t.log.signup(user)
145
- ```
159
+ ```
146
160
 
147
161
  ## License
148
162