r18n-rails-api 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +382 -0
- data/README.md +11 -0
- data/lib/r18n-rails-api/backend.rb +8 -6
- data/lib/r18n-rails-api/filters.rb +4 -6
- data/lib/r18n-rails-api/version.rb +9 -0
- metadata +170 -46
- data/.rspec +0 -1
- data/Rakefile +0 -13
- data/r18n-rails-api.gemspec +0 -33
- data/spec/backend_spec.rb +0 -122
- data/spec/data/general/en.yml +0 -21
- data/spec/data/general/ru.yml +0 -4
- data/spec/data/other/en.yml +0 -2
- data/spec/data/other/ru.yml +0 -2
- data/spec/data/pl/ru.yml +0 -6
- data/spec/data/simple/de-CH.yml +0 -2
- data/spec/data/simple/en.yml +0 -6
- data/spec/data/simple/ru.rb +0 -3
- data/spec/data/simple/russian.yml +0 -2
- data/spec/filters_spec.rb +0 -29
- data/spec/loader_spec.rb +0 -60
- data/spec/spec_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc31abb5763a435459b38f0e32757c14d6a453dcef037c2abf55e80473e6b107
|
4
|
+
data.tar.gz: db25b9933473e2bdd1cd920959535cf63699b27eb29debbe58d567e635e8753c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b87117dfb18e228d13c7277417f1145eb7219ddff500d6ba321bf4fb1ca892f5c0c18609329a84d3c66c42729c801d0819279ffc9ad887506567a050edd92c8
|
7
|
+
data.tar.gz: e5df4f72c9ffb050460f10e7292c658a03d581bf724f9248699528df8a8072ad16f2287f2dac6b5494827731f47a6ac053fbf72972d19d6ae86c3589316dd38a
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,382 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 5.0.0 (Warszawa) (2021-03-04)
|
6
|
+
|
7
|
+
* Take out `r18n-rails-api` 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
|
+
|
20
|
+
## 4.0.0 (Santiago)
|
21
|
+
|
22
|
+
* Drop Ruby 2.3 support (by Alexander Popov).
|
23
|
+
* Drop `R18n::Utils.hash_map` (by Alexander Popov).
|
24
|
+
* Add Ruby 2.6 and 2.7 for CI (by Alexander Popov).
|
25
|
+
* Allow to add custom (per-project) locales (by Alexander Popov).
|
26
|
+
* Add block for `R18n.change` (change affects only code inside block)
|
27
|
+
(by Alexander Popov).
|
28
|
+
* Add `language` and `region` readers for `Locale` (by Alexander Popov).
|
29
|
+
* Allow upcased region in translation file names (like `en-US.yml`)
|
30
|
+
(by Alexander Popov).
|
31
|
+
* Load `base` translations from parent locale (by Alexander Popov).
|
32
|
+
* Downcase locales with regions for `Translated`, like `name_en_us`
|
33
|
+
instead of `name_en-US` (by Alexander Popov).
|
34
|
+
* Add Spanish Chile (`es-CL`) (by Juan Gil Miqueo).
|
35
|
+
* Add `:with_seconds` option for Time formatting (by Alexander Popov).
|
36
|
+
* Replace custom `gsub` in `R18n::Utils.escape_html` with `CGI.escapeHTML`
|
37
|
+
(by Alexander Popov).
|
38
|
+
* Improve Indonesian translation (by Mohammad Satrio).
|
39
|
+
* Improve documentation (by Alexander Popov).
|
40
|
+
* Fix issue with wildcard in `Accept-Language` header (by Alexander Popov).
|
41
|
+
|
42
|
+
## 3.2.0 (Kawasaki)
|
43
|
+
* Support `*.yaml` files (by Alexander Popov).
|
44
|
+
* Locate processed `code` in `UnsupportedLocale`, like in `Locale` (by Alexander Popov).
|
45
|
+
* Fix `TranslatedString#to_ary`, don't return `Untranslated` (by Alexander Popov).
|
46
|
+
* Add Welsh language (`cy`) (by Mei Gwilym).
|
47
|
+
* Add support for custom classes localizing (`R18n.l`) (by Alexander Popov).
|
48
|
+
* Replace blank-padded day in date with no-padded (by Alexander Popov).
|
49
|
+
* Fix `TranslatedString#to_hash` (by Christian Höppner and Alexander Popov).
|
50
|
+
|
51
|
+
## 3.1.2 (i)
|
52
|
+
* Call `Translation#itself` as translation key instead of `Kernel#itself` implementation (by Alexander Popov).
|
53
|
+
|
54
|
+
## 3.1.1 (У)
|
55
|
+
* Fix errors and warnings from `gem build`
|
56
|
+
|
57
|
+
## 3.1 (Одинцово)
|
58
|
+
* Move `named_variables` filter from `r18n-rails-api` to `r18n-core` (by Alexander Popov).
|
59
|
+
* Add possibility for `R18n::Locale` to define custom formatters (by Alexander Popov).
|
60
|
+
* Fix `R18n.set` for `r18n-desktop` (by Alexander Popov).
|
61
|
+
|
62
|
+
## 3.0.5 (ب)
|
63
|
+
* Fix Farsi locale name (by @iriman).
|
64
|
+
|
65
|
+
## 3.0.4 (𐤀)
|
66
|
+
* Fix `Translated` compatibility with `Hash` (by Alexander Popov).
|
67
|
+
|
68
|
+
## 3.0.3 (〥)
|
69
|
+
* Fix missed filters in `Untranslted` initialization (by Alexander Popov).
|
70
|
+
|
71
|
+
## 3.0.2 (Ё)
|
72
|
+
* Fix `Untranslted.to_s` (by Patrik Rak).
|
73
|
+
|
74
|
+
## 3.0.1 (Brooklyn)
|
75
|
+
* Fix `no` locale deprecation warning.
|
76
|
+
|
77
|
+
## 3.0 (New York)
|
78
|
+
* Deprecate `no` locale, use `nb` instead (by Alexander Popov).
|
79
|
+
* Remove unsafe `!!proc` filter.
|
80
|
+
* Reduce `eval` calls (by Alexander Popov).
|
81
|
+
|
82
|
+
## 2.2 (La Habana)
|
83
|
+
* Change date format in `en` locale to `YYYY-MM-DD` (by Alexander Popov).
|
84
|
+
* Add `TranslatedString#as_json` for ActiveSupport compatibility (by Tim Craft).
|
85
|
+
* Fix `TranslatedString#html_safe?` behavior (by Tim Craft).
|
86
|
+
* Fix unsupported `LANG` environment (by Chris Poirier).
|
87
|
+
* Fix `Locale#localize` method for `DateTime` objects (by Alexander Popov).
|
88
|
+
|
89
|
+
## 2.1.8 (Ѣ)
|
90
|
+
* Fix `true` and `false` keys support (by Alexander Popov).
|
91
|
+
|
92
|
+
## 2.1.7 (Sewe)
|
93
|
+
* Add Afrikaans locale (by Llewellyn van der Merwe).
|
94
|
+
|
95
|
+
## 2.1.6 (Berlin)
|
96
|
+
* Better `TranslatedString` → `String` converting (by Patrik Rak).
|
97
|
+
* Add Ruby on Rails 5 support.
|
98
|
+
|
99
|
+
## 2.1.5 (මාතර)
|
100
|
+
* Fix Ruby 2.4 support (by Alexander Popov)
|
101
|
+
|
102
|
+
## 2.1.4 (Bakı)
|
103
|
+
* Add Azerbaijani locale (by Adil Aliyev).
|
104
|
+
|
105
|
+
## 2.1.3 (Seoul)
|
106
|
+
* Add Korean locale (by Patrick Cheng).
|
107
|
+
|
108
|
+
## 2.1.2 (Wien)
|
109
|
+
* Fix Ruby 2.3 support.
|
110
|
+
|
111
|
+
## 2.1.1 (Barcelona)
|
112
|
+
* Better sanity check for Accept-Language header (by Viktors Rotanovs).
|
113
|
+
|
114
|
+
## 2.1 (Một)
|
115
|
+
* Add Vietnamese locale (by Nguyễn Văn Được).
|
116
|
+
* Add Persian locale.
|
117
|
+
* Allow to change date/time order in locales.
|
118
|
+
* Fix pluralization in locales without plural forms.
|
119
|
+
* Fix Mongolian base translations.
|
120
|
+
|
121
|
+
## 2.0.4 (Ikkuna)
|
122
|
+
* Fix Windows support (by janahanEDH).
|
123
|
+
|
124
|
+
## 2.0.3 (Hévíz)
|
125
|
+
* Fix Thai locale (by Kasima Tharnpipitchai).
|
126
|
+
|
127
|
+
## 2.0.2 (Budapest)
|
128
|
+
* Fix array support in translations.
|
129
|
+
* Fix Rails support for dialect locales.
|
130
|
+
|
131
|
+
## 2.0.1 (Amsterdam)
|
132
|
+
* Fix Dutch locale.
|
133
|
+
|
134
|
+
## 2.0.0 (Москва)
|
135
|
+
* Remove Ruby 1.8 and 1.9 support.
|
136
|
+
* Add JRuby 9000 support.
|
137
|
+
|
138
|
+
### 1.1.11 (São Paulo)
|
139
|
+
* Allow to set Proc as `default` option in Rails I18n back-end.
|
140
|
+
|
141
|
+
### 1.1.10 (十)
|
142
|
+
* Fix Esperanto locale by Larry Gilbert.
|
143
|
+
* Fix Chinese locale (by 刘当一).
|
144
|
+
|
145
|
+
### 1.1.9 (Не знайдено)
|
146
|
+
* Fix Rails 4.0.4 support. Prevent loop on `enforce_available_locales`.
|
147
|
+
|
148
|
+
### 1.1.8 (Osam)
|
149
|
+
* Add Croatian locale (by Dino Kovač).
|
150
|
+
* Add Serbian latin locale (by Dino Kovač).
|
151
|
+
|
152
|
+
### 1.1.7 (Tujuh)
|
153
|
+
* Return `nil` on untranslated in models with Translated.
|
154
|
+
* Add `transliterate` method to I18n back-end.
|
155
|
+
* Add Indonesian locale (by Guntur Akhmad).
|
156
|
+
|
157
|
+
### 1.1.6 (Vitebsk)
|
158
|
+
* Return `TranslatedString` after global String filters.
|
159
|
+
* Fix path in global String filters.
|
160
|
+
|
161
|
+
### 1.1.5 (Hilo)
|
162
|
+
* Fix Sinatra plugin under multi-threaded web-server (by Viktors Rotanovs).
|
163
|
+
* Fix `BigDecimal` localizing (by François Beausoleil).
|
164
|
+
* Add American American Spanish locale (by renemarcelo).
|
165
|
+
|
166
|
+
### 1.1.4 (Bokmål)
|
167
|
+
* Add Norwegian `no` locale as gateway to Bokmål or Nynorsk.
|
168
|
+
* Fix Norwegian Bokmål locale code.
|
169
|
+
* Fix Hungarian time format (Kővágó Zoltán).
|
170
|
+
|
171
|
+
### 1.1.3 (Saint Petersburg)
|
172
|
+
* Fix memory leak from cache key mismatch in Rails plugin (by silentshade).
|
173
|
+
|
174
|
+
### 1.1.2 (Marshal)
|
175
|
+
* Fix translation and untranslated marshalizing (by silentshade).
|
176
|
+
* Allow to compare untranslated strings.
|
177
|
+
* Fix untranslated strings output in tests.
|
178
|
+
|
179
|
+
### 1.1.1 (Dunhuang)
|
180
|
+
* Don't change YAML parser in Ruby 1.9.
|
181
|
+
* Allow to change locale by argument in R18n Rails back-end.
|
182
|
+
* Set also Rails I18n locale in Rails auto-detect filter.
|
183
|
+
* Fix caching with custom filters (by Anton Onyshchenko).
|
184
|
+
* Fix translation variables with `%1` text inside (by Taras Kunch).
|
185
|
+
* Fix Latvian locale (by Aleksandrs Ļedovskis).
|
186
|
+
|
187
|
+
### 1.1.0 (Leipzig)
|
188
|
+
* A lot of fixes in Rails I18n compatibility (thanks for Stephan Schubert).
|
189
|
+
* Return `Untranslted`, when user try to call another translation key on
|
190
|
+
already translated string.
|
191
|
+
* Add `Translation#to_hash` to get raw translation.
|
192
|
+
* Add `Translation#inspect` to easy debug.
|
193
|
+
* Return translation, when pluralization filter did not get count.
|
194
|
+
* Set R18n back-end on Rails plugin init, to use it in console.
|
195
|
+
* Allow to use Integer in translation keys.
|
196
|
+
|
197
|
+
### 1.0.1 (Phuket Town)
|
198
|
+
* Fix translation reloading in Rails and Sinatra.
|
199
|
+
* Use global R18n settings for Sinatra extension.
|
200
|
+
* Allow to override desktop auto-detect by LANG environment on all platforms.
|
201
|
+
* Add support for JRuby in 1.9 mode.
|
202
|
+
* Rename `R18n.reset` to `R18n.reset!` and add `R18n.clear_cache!`.
|
203
|
+
* Fix Sinatra with loaded ActiveSupport.
|
204
|
+
* Add Mongolian locale (by Elias Klughammer).
|
205
|
+
|
206
|
+
### 1.0.0 (Bangkok)
|
207
|
+
* Add `R18n.default_places`.
|
208
|
+
* Rails `SafeBuffer` support.
|
209
|
+
* Allow in Rails app to put filters to `app/i18n` reload them in development.
|
210
|
+
* Move `R18n::I18n.available_locales` to `R18n.available_locales`.
|
211
|
+
* Rename `_keys` to `translation_keys`.
|
212
|
+
* Use Kramdown instead of Maruku for Markdown.
|
213
|
+
* Allow to use R18n for Rails without mailer.
|
214
|
+
* Allow to overwrite I18n object for models.
|
215
|
+
* Autoload R18n::Translated.
|
216
|
+
* Set default locale to R18n on Rails start to easy use in Rails console.
|
217
|
+
* Use env language in Rails console.
|
218
|
+
* Mark untranslated part as red in Rails console.
|
219
|
+
* Allow to temporary change locale by `R18n.change`.
|
220
|
+
* Add `R18n.locale` shortcut.
|
221
|
+
* Allow return from setter block locale code, instead of I18n object.
|
222
|
+
* Allow to set custom filters for I18n object.
|
223
|
+
* Add Galician locale (by Eduard Giménez).
|
224
|
+
* Add Traditional Chinese and Simplified Chinese (by Francis Chong).
|
225
|
+
* Fix Norsk locale (by Peter Haza).
|
226
|
+
|
227
|
+
### 0.4.14 (üç)
|
228
|
+
* Fix support for Ruby 1.9.3.
|
229
|
+
* Added Turkish locale (by Ahmet Özkaya).
|
230
|
+
* Fix Swedish locale (by Pär Wieslander).
|
231
|
+
|
232
|
+
### 0.4.13 (Sti)
|
233
|
+
* Fix `Pathname` to `String` error in `r18n-desktop`.
|
234
|
+
* Add Norwegian locale (by Oddmund Strømme).
|
235
|
+
|
236
|
+
### 0.4.12 (Шлях)
|
237
|
+
* Fix `Pathname` to `String` conversion error.
|
238
|
+
* Fix model translation for non-ActiveRecord (by Szymon Przybył).
|
239
|
+
* Add Ukrainian locale (by Ярослав Руденок).
|
240
|
+
|
241
|
+
### 0.4.11 (Nancy)
|
242
|
+
* Support for Sinatra 1.3.
|
243
|
+
* Fix JRuby support by Paul Walker.
|
244
|
+
* Add R18n helpers to Rails mailer by Alexey Medvedev.
|
245
|
+
|
246
|
+
### 0.4.10 (Kvantum)
|
247
|
+
* Add R18n.set(locales, places), R18n.t and R18n.l shortcuts.
|
248
|
+
* Convert float to number on pluralization.
|
249
|
+
* Fix loading empty translation file.
|
250
|
+
* Add Portuguese locale.
|
251
|
+
* Add Dutch locale (by Sander Heilbron).
|
252
|
+
* Add Swedish locale (by Magnus Hörberg).
|
253
|
+
|
254
|
+
### 0.4.9 (Kazan)
|
255
|
+
* Add support for Psych YAML parser (thanks for Ravil Bayramgalin).
|
256
|
+
* Fix ActiveRecord support in Translated.
|
257
|
+
* Fix Translated to return non-string values.
|
258
|
+
* Fix human time localization.
|
259
|
+
* Add Bulgarian locale (by Mitko Kostov).
|
260
|
+
* Add Australian English locale (by Dave Sag).
|
261
|
+
|
262
|
+
### 0.4.8 (En ni to)
|
263
|
+
* Fix support for Ruby 1.9.2.
|
264
|
+
* Fix caching issue (by Viktors Rotanovs).
|
265
|
+
* Add Danish locale (by Hans Czajkowski Jørgensen)
|
266
|
+
* Fix Italian locale (by Viktors Rotanovs).
|
267
|
+
* Move untranslated filters with html highlight to `r18n-core`.
|
268
|
+
|
269
|
+
### 0.4.7.1 (Kyū)
|
270
|
+
* Fix Japanese locale in Ruby 1.9.1.
|
271
|
+
|
272
|
+
### 0.4.7 (Mado)
|
273
|
+
* Fix auto-detect locale in Windows and Ruby 1.9.1 (by Marvin Gülker).
|
274
|
+
* Fix auto-detect locale in JRuby (by Kővágó, Zoltán).
|
275
|
+
* Fix human time format on 60 minutes.
|
276
|
+
* Add Hungarian locale (by Kővágó, Zoltán).
|
277
|
+
* Add Japanese locale (by hryk).
|
278
|
+
* Fix Polish locale (by Piotr Szotkowski).
|
279
|
+
|
280
|
+
### 0.4.6 (Trinity)
|
281
|
+
* Add support for new interpolation syntax in Rails 3.
|
282
|
+
* Add Catalian locale (by Jordi Romero).
|
283
|
+
* Add Finish locale (by Laura Guillén).
|
284
|
+
* Add British locale (by JP Hastings-Spital).
|
285
|
+
* Add Latvian locale (by Iļja Ketris).
|
286
|
+
* Fix Spanish (by Jordi Romero), German, French, Esperanto (by Iļja Ketris) and
|
287
|
+
Polish locales.
|
288
|
+
* Fix documentation (by Iļja Ketris and felix).
|
289
|
+
* Remove RubyGems from plugins requires.
|
290
|
+
|
291
|
+
### 0.4.5 (Annual)
|
292
|
+
* Filters for several types.
|
293
|
+
* Global HTML escaping run before Markdown and Textile formatting.
|
294
|
+
* Fix active filters after passive filters.
|
295
|
+
* Fix human time formatting for dates with same month days.
|
296
|
+
|
297
|
+
### 0.4.4 (Frank)
|
298
|
+
* Use before filter to lazy set I18n object in Sinatra extension.
|
299
|
+
* Set I18n object to thread (by Simon Hafner).
|
300
|
+
* Add to l Rails helper R18n syntax.
|
301
|
+
* Add common helpers.
|
302
|
+
* Clear cache in `R18n.reset`.
|
303
|
+
* Clean up code and fix bug (by Akzhan Abdulin).
|
304
|
+
* Add Thai locale (by Felix Hanley).
|
305
|
+
|
306
|
+
### 0.4.3 (Flange)
|
307
|
+
* Add R18n style methods to Rails controllers.
|
308
|
+
* Fix for non-string translations in Rails I18n.
|
309
|
+
* Use default locale from Rails I18n config.
|
310
|
+
* Load translations recursively.
|
311
|
+
* Add Slovak locale (by Ahmed Al Hafoudh)
|
312
|
+
|
313
|
+
### 0.4.2 (EMS)
|
314
|
+
* Fixes for Ruby 1.8.6 (by Akzhan Abdulin).
|
315
|
+
* Add method to get translation keys.
|
316
|
+
|
317
|
+
### 0.4.1 (Lazy Boole)
|
318
|
+
* Add passive filters.
|
319
|
+
* Receive filter position as option `Hash`.
|
320
|
+
* Fix base translations (by Pavel Kunc).
|
321
|
+
|
322
|
+
### 0.4 (D-Day)
|
323
|
+
* Rails I18n compatibility.
|
324
|
+
* Rewrite a lot of core code to fast and cleanup version.
|
325
|
+
* Custom translation loaders.
|
326
|
+
* Add reload! method to I18n.
|
327
|
+
* Add t and l helpers to Sinatra and desktop plugins.
|
328
|
+
* Syntax sugar for default values.
|
329
|
+
* Named variables.
|
330
|
+
* New locale API.
|
331
|
+
* Change API for extension translations.
|
332
|
+
|
333
|
+
### 0.3.2 (Pidgin)
|
334
|
+
* Print path of untranslated string by filters.
|
335
|
+
* Add Italian locale (by Guido De Rosa).
|
336
|
+
* Fix Polish locale (by Adrian Pacała).
|
337
|
+
* Fix American English locale (by Max Aller).
|
338
|
+
|
339
|
+
### 0.3.1 (Yield)
|
340
|
+
* Add Chinese locale (by Ilia Zayats).
|
341
|
+
* Add Spanish locale (by Andre O Moura).
|
342
|
+
* Add Brazilian Portuguese locale (by Andre O Moura).
|
343
|
+
* Remove RubyGems requires.
|
344
|
+
|
345
|
+
### 0.3 (Vladivostok)
|
346
|
+
* `Translated` mixin to I18n support to model or any other class.
|
347
|
+
* New cool time formatters.
|
348
|
+
* Filters for translations.
|
349
|
+
* Add filters to escape HTML, Markdown and Textile syntax.
|
350
|
+
* Pluralization and variables is now filters and can be replaced.
|
351
|
+
* I18n#locales now contain all detected locales, used to load translations,
|
352
|
+
instead of just received from user.
|
353
|
+
* Bug-fix in locale code case.
|
354
|
+
* Add Czech locale (by Josef Pospíšil).
|
355
|
+
|
356
|
+
### 0.2.3 (Shanghai eclipse)
|
357
|
+
* R18n will return path string if translation isn't exists.
|
358
|
+
* Add `UnsupportedLocale` class for locale without information file.
|
359
|
+
* Load absent locale information from default locale.
|
360
|
+
* Add Polish locale (by Tymon Tobolski).
|
361
|
+
|
362
|
+
### 0.2.2 (Clone Wars)
|
363
|
+
* Localize numbers in pluralization.
|
364
|
+
* Bug-fix in translation variables.
|
365
|
+
|
366
|
+
### 0.2.1 (Neun)
|
367
|
+
* Ruby 1.9 compatibility.
|
368
|
+
* Add German locale (by Benjamin Meichsner).
|
369
|
+
|
370
|
+
### 0.2 (Freedom of Language)
|
371
|
+
* Locale class can be extended for special language (for example, Indian locale
|
372
|
+
may has another digits grouping).
|
373
|
+
* Load translations from several dirs.
|
374
|
+
* Add French locale.
|
375
|
+
* Add Kazakh locale.
|
376
|
+
|
377
|
+
### 0.1.1 (Saluto)
|
378
|
+
* Loading I18n object without translations.
|
379
|
+
* Add output for standalone month name.
|
380
|
+
* Don't call procedures from translations if it isn't secure.
|
381
|
+
* Add Esperanto locale.
|
382
|
+
* English locale now contain UK date standards.
|
data/README.md
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
# R18n Rails API
|
2
2
|
|
3
|
+
[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/r18n/r18n-rails-api?style=flat-square)](https://cirrus-ci.com/github/r18n/r18n-rails-api)
|
4
|
+
[![Codecov branch](https://img.shields.io/codecov/c/github/r18n/r18n-rails-api/master.svg?style=flat-square)](https://codecov.io/gh/r18n/r18n-rails-api)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/maintainability/r18n/r18n-rails-api.svg?style=flat-square)](https://codeclimate.com/github/r18n/r18n-rails-api)
|
6
|
+
[![Depfu](https://img.shields.io/depfu/r18n/r18n-rails-api?style=flat-square)](https://depfu.com/repos/github/r18n/r18n-rails-api)
|
7
|
+
[![License](https://img.shields.io/github/license/r18n/r18n-rails-api.svg?style=flat-square)](LICENSE)
|
8
|
+
[![Gem](https://img.shields.io/gem/v/r18n-rails-api.svg?style=flat-square)](https://rubygems.org/gems/r18n-rails-api)
|
9
|
+
|
3
10
|
Rails I18n compatibility for R18n:
|
4
11
|
* R18n loader for Rails I18n translation format;
|
5
12
|
* R18n back-end.
|
6
13
|
|
14
|
+
It is just a wrapper for [R18n core library](https://github.com/r18n/r18n-core).
|
15
|
+
See [R18n documentation](https://github.com/r18n/r18n-core/blob/master/README.md)
|
16
|
+
for more information.
|
17
|
+
|
7
18
|
## How To
|
8
19
|
|
9
20
|
### Rails Translations
|
@@ -49,10 +49,11 @@ module R18n
|
|
49
49
|
default = [default] unless default.is_a? Array
|
50
50
|
|
51
51
|
default.each do |entry|
|
52
|
-
|
52
|
+
case entry
|
53
|
+
when Symbol
|
53
54
|
value = lookup(locale, scope, entry, separator, params)
|
54
55
|
return value unless value.is_a? Untranslated
|
55
|
-
|
56
|
+
when Proc
|
56
57
|
proc_key = options.delete(:object) || key
|
57
58
|
return entry.call(proc_key, options)
|
58
59
|
else
|
@@ -102,11 +103,12 @@ module R18n
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def format_value(result)
|
105
|
-
|
106
|
+
case result
|
107
|
+
when TranslatedString
|
106
108
|
result.to_s
|
107
|
-
|
108
|
-
result.to_hash.
|
109
|
-
|
109
|
+
when UnpluralizedTranslation
|
110
|
+
result.to_hash.transform_keys { |key| RailsPlural.from_r18n(key) }
|
111
|
+
when Translation
|
110
112
|
translation_to_hash(result)
|
111
113
|
else
|
112
114
|
result
|
@@ -27,9 +27,7 @@ R18n::Filters.add(String, :named_variables) do |content, config, params|
|
|
27
27
|
content = content.clone
|
28
28
|
params.each_pair do |name, value|
|
29
29
|
value = config[:locale].localize(value)
|
30
|
-
if defined? ActiveSupport::SafeBuffer
|
31
|
-
value = ActiveSupport::SafeBuffer.new + value
|
32
|
-
end
|
30
|
+
value = ActiveSupport::SafeBuffer.new + value if defined? ActiveSupport::SafeBuffer
|
33
31
|
content.gsub! "%{#{name}}", value
|
34
32
|
content.gsub! "{{#{name}}}", value
|
35
33
|
end
|
@@ -39,7 +37,7 @@ end
|
|
39
37
|
|
40
38
|
module R18n
|
41
39
|
# Class to mark unpluralized translation and convert Rails plural keys
|
42
|
-
class
|
40
|
+
class RailsUnpluralizedTranslation < UnpluralizedTranslation
|
43
41
|
def [](name, *params)
|
44
42
|
result = super
|
45
43
|
if result.is_a? Untranslated
|
@@ -58,8 +56,8 @@ R18n::Filters.add('pl', :named_pluralization) do |content, config, param|
|
|
58
56
|
type = config[:locale].pluralize(param[:count])
|
59
57
|
type = 'n' unless hash.key?(type)
|
60
58
|
hash[type]
|
61
|
-
elsif content.is_a? R18n::
|
62
|
-
R18n::
|
59
|
+
elsif content.is_a? R18n::UnpluralizedTranslation
|
60
|
+
R18n::RailsUnpluralizedTranslation.new(
|
63
61
|
config[:locale], config[:path],
|
64
62
|
locale: config[:locale], translations: content.to_hash
|
65
63
|
)
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-rails-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
|
-
|
8
|
+
- Alexander Popov
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2021-03-03 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: i18n
|
@@ -16,28 +17,168 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
20
|
+
version: '1.0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
27
|
+
version: '1.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: r18n-core
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- -
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
+
version: '5.0'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- -
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '5.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry-byebug
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.9'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.9'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: gem_toys
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.7.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.7.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: toys
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.11.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.11.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.6'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.6'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop-performance
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.9'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '1.9'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop-rails
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '2.9'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.9'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop-rake
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.5.1
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 0.5.1
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: codecov
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 0.5.0
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.5.0
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: rspec
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '3.10'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
39
166
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
167
|
+
version: '3.10'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: simplecov
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 0.21.0
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 0.21.0
|
41
182
|
description: |2
|
42
183
|
R18n backend for Rails I18n and R18n filters and loader to support Rails
|
43
184
|
translation format.
|
@@ -45,41 +186,34 @@ description: |2
|
|
45
186
|
translation support for any classes, time and number localization, several
|
46
187
|
user language support, agnostic core package with out-of-box support for
|
47
188
|
Rails, Sinatra and desktop applications.
|
48
|
-
email:
|
189
|
+
email:
|
190
|
+
- andrey@sitnik.ru
|
191
|
+
- alex.wayfer@gmail.com
|
49
192
|
executables: []
|
50
193
|
extensions: []
|
51
194
|
extra_rdoc_files:
|
52
195
|
- README.md
|
53
196
|
- LICENSE
|
54
197
|
files:
|
55
|
-
-
|
198
|
+
- ChangeLog.md
|
56
199
|
- LICENSE
|
57
200
|
- README.md
|
58
|
-
- Rakefile
|
59
201
|
- lib/r18n-rails-api.rb
|
60
202
|
- lib/r18n-rails-api/backend.rb
|
61
203
|
- lib/r18n-rails-api/filters.rb
|
62
204
|
- lib/r18n-rails-api/loader.rb
|
63
205
|
- lib/r18n-rails-api/rails_plural.rb
|
64
|
-
- r18n-rails-api.
|
65
|
-
|
66
|
-
- spec/data/general/en.yml
|
67
|
-
- spec/data/general/ru.yml
|
68
|
-
- spec/data/other/en.yml
|
69
|
-
- spec/data/other/ru.yml
|
70
|
-
- spec/data/pl/ru.yml
|
71
|
-
- spec/data/simple/de-CH.yml
|
72
|
-
- spec/data/simple/en.yml
|
73
|
-
- spec/data/simple/ru.rb
|
74
|
-
- spec/data/simple/russian.yml
|
75
|
-
- spec/filters_spec.rb
|
76
|
-
- spec/loader_spec.rb
|
77
|
-
- spec/spec_helper.rb
|
78
|
-
homepage: https://github.com/r18n/r18n/tree/master/r18n-rails-api
|
206
|
+
- lib/r18n-rails-api/version.rb
|
207
|
+
homepage: https://github.com/r18n/r18n-rails-api
|
79
208
|
licenses:
|
80
209
|
- LGPL-3.0
|
81
|
-
metadata:
|
82
|
-
|
210
|
+
metadata:
|
211
|
+
bug_tracker_uri: https://github.com/r18n/r18n-rails-api/issues
|
212
|
+
changelog_uri: https://github.com/r18n/r18n-rails-api/blob/5.0.0/ChangeLog.md
|
213
|
+
documentation_uri: http://www.rubydoc.info/gems/r18n-rails-api/5.0.0
|
214
|
+
homepage_uri: https://github.com/r18n/r18n-rails-api
|
215
|
+
source_code_uri: https://github.com/r18n/r18n-rails-api
|
216
|
+
post_install_message:
|
83
217
|
rdoc_options: []
|
84
218
|
require_paths:
|
85
219
|
- lib
|
@@ -87,28 +221,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
221
|
requirements:
|
88
222
|
- - ">="
|
89
223
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
224
|
+
version: '2.5'
|
225
|
+
- - "<"
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '4'
|
91
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
229
|
requirements:
|
93
230
|
- - ">="
|
94
231
|
- !ruby/object:Gem::Version
|
95
232
|
version: '0'
|
96
233
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
98
|
-
signing_key:
|
234
|
+
rubygems_version: 3.2.3
|
235
|
+
signing_key:
|
99
236
|
specification_version: 4
|
100
237
|
summary: Rails I18n compatibility for R18n
|
101
|
-
test_files:
|
102
|
-
- spec/backend_spec.rb
|
103
|
-
- spec/data/general/en.yml
|
104
|
-
- spec/data/general/ru.yml
|
105
|
-
- spec/data/other/en.yml
|
106
|
-
- spec/data/other/ru.yml
|
107
|
-
- spec/data/pl/ru.yml
|
108
|
-
- spec/data/simple/de-CH.yml
|
109
|
-
- spec/data/simple/en.yml
|
110
|
-
- spec/data/simple/ru.rb
|
111
|
-
- spec/data/simple/russian.yml
|
112
|
-
- spec/filters_spec.rb
|
113
|
-
- spec/loader_spec.rb
|
114
|
-
- spec/spec_helper.rb
|
238
|
+
test_files: []
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--format documentation --colour --warnings --require spec_helper
|
data/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
Bundler::GemHelper.install_tasks
|
5
|
-
|
6
|
-
require 'rspec/core/rake_task'
|
7
|
-
RSpec::Core::RakeTask.new
|
8
|
-
task default: :spec
|
9
|
-
|
10
|
-
task :clobber_package do
|
11
|
-
rm_rf 'pkg'
|
12
|
-
end
|
13
|
-
task clobber: [:clobber_package]
|
data/r18n-rails-api.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../r18n-core/lib/r18n-core/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.platform = Gem::Platform::RUBY
|
7
|
-
s.name = 'r18n-rails-api'
|
8
|
-
s.version = R18n::VERSION.dup
|
9
|
-
s.date = Time.now.strftime('%Y-%m-%d')
|
10
|
-
|
11
|
-
s.summary = 'Rails I18n compatibility for R18n'
|
12
|
-
s.description = <<-DESC
|
13
|
-
R18n backend for Rails I18n and R18n filters and loader to support Rails
|
14
|
-
translation format.
|
15
|
-
R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,
|
16
|
-
translation support for any classes, time and number localization, several
|
17
|
-
user language support, agnostic core package with out-of-box support for
|
18
|
-
Rails, Sinatra and desktop applications.
|
19
|
-
DESC
|
20
|
-
|
21
|
-
s.files = `git ls-files`.split("\n")
|
22
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
-
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
24
|
-
s.require_path = 'lib'
|
25
|
-
|
26
|
-
s.author = 'Andrey Sitnik'
|
27
|
-
s.email = 'andrey@sitnik.ru'
|
28
|
-
s.homepage = 'https://github.com/r18n/r18n/tree/master/r18n-rails-api'
|
29
|
-
s.license = 'LGPL-3.0'
|
30
|
-
|
31
|
-
s.add_dependency 'i18n', '~> 1'
|
32
|
-
s.add_dependency 'r18n-core', "= #{R18n::VERSION}"
|
33
|
-
end
|
data/spec/backend_spec.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe R18n::Backend do
|
4
|
-
before do
|
5
|
-
I18n.load_path = [GENERAL]
|
6
|
-
I18n.backend = R18n::Backend.new
|
7
|
-
R18n.default_places = R18n::Loader::Rails.new
|
8
|
-
R18n.set('en')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'returns available locales' do
|
12
|
-
expect(I18n.available_locales).to match_array(%i[en ru])
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'localizes objects' do
|
16
|
-
time = Time.at(0).utc
|
17
|
-
date = Date.parse('1970-01-01')
|
18
|
-
|
19
|
-
expect(I18n.l(time)).to eq 'Thu, 01 Jan 1970 00:00:00 +0000'
|
20
|
-
expect(I18n.l(date)).to eq '1970-01-01'
|
21
|
-
|
22
|
-
expect(I18n.l(time, format: :short)).to eq '01 Jan 00:00'
|
23
|
-
expect(I18n.l(time, format: :full)).to eq '1st of January, 1970 00:00'
|
24
|
-
|
25
|
-
expect(I18n.l(-5000.5)).to eq '−5,000.5'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'translates by key and scope' do
|
29
|
-
expect(I18n.t('in.another.level')).to eq 'Hierarchical'
|
30
|
-
expect(I18n.t(:level, scope: 'in.another')).to eq 'Hierarchical'
|
31
|
-
expect(I18n.t(:'another.level', scope: 'in')).to eq 'Hierarchical'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'uses pluralization and variables' do
|
35
|
-
expect(I18n.t('users', count: 0)).to eq '0 users'
|
36
|
-
expect(I18n.t('users', count: 1)).to eq '1 user'
|
37
|
-
expect(I18n.t('users', count: 5)).to eq '5 users'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'uses another separator' do
|
41
|
-
expect(I18n.t('in/another/level', separator: '/')).to eq 'Hierarchical'
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'translates array' do
|
45
|
-
expect(I18n.t(['in.another.level', 'in.default'])).to eq(
|
46
|
-
%w[Hierarchical Default]
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'uses default value' do
|
51
|
-
expect(I18n.t(:missed, default: 'Default')).to eq 'Default'
|
52
|
-
expect(I18n.t(:missed, default: :default, scope: :in)).to eq 'Default'
|
53
|
-
expect(I18n.t(:missed, default: %i[also_no in.default])).to eq 'Default'
|
54
|
-
expect(I18n.t(:missed, default: proc { |key| key.to_s })).to eq 'missed'
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'raises error on no translation' do
|
58
|
-
expect { I18n.backend.translate(:en, :missed) }
|
59
|
-
.to raise_error(::I18n::MissingTranslationData)
|
60
|
-
|
61
|
-
expect { I18n.t(:missed) }.to raise_error(::I18n::MissingTranslationData)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'reloads translations' do
|
65
|
-
expect { I18n.t(:other) }.to raise_error(::I18n::MissingTranslationData)
|
66
|
-
I18n.load_path << OTHER
|
67
|
-
I18n.reload!
|
68
|
-
expect(I18n.t(:other)).to eq 'Other'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'returns plain classes' do
|
72
|
-
expect(I18n.t('in.another.level').class).to eq ActiveSupport::SafeBuffer
|
73
|
-
expect(I18n.t('in.another').class).to eq Hash
|
74
|
-
end
|
75
|
-
|
76
|
-
## https://github.com/rubocop-hq/rubocop/issues/7436#issuecomment-578766498
|
77
|
-
# rubocop:disable Style/FormatStringToken
|
78
|
-
it 'returns correct unpluralized hash' do
|
79
|
-
expect(I18n.t('users')).to eq(one: '1 user', other: '%{count} users')
|
80
|
-
end
|
81
|
-
# rubocop:enable Style/FormatStringToken
|
82
|
-
|
83
|
-
it 'corrects detect untranslated, whem path is deeper than string' do
|
84
|
-
expect { I18n.t('in.another.level.deeper') }
|
85
|
-
.to raise_error(::I18n::MissingTranslationData)
|
86
|
-
|
87
|
-
expect { I18n.t('in.another.level.go.deeper') }
|
88
|
-
.to raise_error(::I18n::MissingTranslationData)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "doesn't call String methods" do
|
92
|
-
expect(I18n.t('in.another').class).to eq Hash
|
93
|
-
end
|
94
|
-
|
95
|
-
it "doesn't call object methods" do
|
96
|
-
expect { I18n.t('in.another.level.to_sym') }
|
97
|
-
.to raise_error(::I18n::MissingTranslationData)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'works deeper pluralization' do
|
101
|
-
expect(I18n.t('users.other', count: 5)).to eq '5 users'
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'returns hash with symbols keys' do
|
105
|
-
expect(I18n.t('in')).to eq(
|
106
|
-
another: { level: 'Hierarchical' },
|
107
|
-
default: 'Default'
|
108
|
-
)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'changes locale in place' do
|
112
|
-
I18n.load_path << PL
|
113
|
-
expect(I18n.t('users', count: 5)).to eq '5 users'
|
114
|
-
expect(I18n.t('users', count: 5, locale: :ru)).to eq 'Много'
|
115
|
-
|
116
|
-
expect(I18n.l(Date.parse('1970-01-01'), locale: :ru)).to eq '01.01.1970'
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'has transliterate method' do
|
120
|
-
expect(I18n.transliterate('café')).to eq 'cafe'
|
121
|
-
end
|
122
|
-
end
|
data/spec/data/general/en.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
date:
|
3
|
-
formats:
|
4
|
-
default: "%Y-%m-%d"
|
5
|
-
short: "%b %d"
|
6
|
-
long: "%B %d, %Y"
|
7
|
-
|
8
|
-
time:
|
9
|
-
formats:
|
10
|
-
default: "%a, %d %b %Y %H:%M:%S %z"
|
11
|
-
short: "%d %b %H:%M"
|
12
|
-
long: "%B %d, %Y %H:%M"
|
13
|
-
|
14
|
-
in:
|
15
|
-
another:
|
16
|
-
level: Hierarchical
|
17
|
-
default: Default
|
18
|
-
|
19
|
-
users:
|
20
|
-
one: 1 user
|
21
|
-
other: "%{count} users"
|
data/spec/data/general/ru.yml
DELETED
data/spec/data/other/en.yml
DELETED
data/spec/data/other/ru.yml
DELETED
data/spec/data/pl/ru.yml
DELETED
data/spec/data/simple/de-CH.yml
DELETED
data/spec/data/simple/en.yml
DELETED
data/spec/data/simple/ru.rb
DELETED
data/spec/filters_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe 'Rails filters' do
|
4
|
-
it 'uses old variables syntax' do
|
5
|
-
i18n = R18n::Translation.new(
|
6
|
-
EN, '', locale: EN, translations: { 'echo' => 'Value is {{value}}' }
|
7
|
-
)
|
8
|
-
expect(i18n.echo(value: 'Old')).to eq 'Value is Old'
|
9
|
-
end
|
10
|
-
|
11
|
-
# rubocop:disable Style/FormatStringToken
|
12
|
-
it 'pluralizes by variable %{count}' do
|
13
|
-
i18n = R18n::Translation.new(
|
14
|
-
EN, '', locale: EN, translations: {
|
15
|
-
'users' => R18n::Typed.new(
|
16
|
-
'pl',
|
17
|
-
0 => 'no users',
|
18
|
-
1 => '1 user',
|
19
|
-
'n' => '%{count} users'
|
20
|
-
)
|
21
|
-
}
|
22
|
-
)
|
23
|
-
|
24
|
-
expect(i18n.users(count: 0)).to eq 'no users'
|
25
|
-
expect(i18n.users(count: 1)).to eq '1 user'
|
26
|
-
expect(i18n.users(count: 5)).to eq '5 users'
|
27
|
-
end
|
28
|
-
# rubocop:enable Style/FormatStringToken
|
29
|
-
end
|
data/spec/loader_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe R18n::Loader::Rails do
|
4
|
-
before do
|
5
|
-
I18n.load_path = [SIMPLE]
|
6
|
-
@loader = R18n::Loader::Rails.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns available locales' do
|
10
|
-
expect(@loader.available).to match_array([DECH, EN, RU])
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'loads translation' do
|
14
|
-
expect(@loader.load(RU)).to eq('one' => 'Один', 'two' => 'Два')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'loads translation for dialects' do
|
18
|
-
expect(@loader.load(DECH)).to eq('a' => 1)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'changes pluralization' do
|
22
|
-
expect(@loader.load(EN)).to eq(
|
23
|
-
'users' => R18n::Typed.new(
|
24
|
-
'pl',
|
25
|
-
0 => 'Zero',
|
26
|
-
1 => 'One',
|
27
|
-
2 => 'Few',
|
28
|
-
'n' => 'Other'
|
29
|
-
)
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'changes Russian pluralization' do
|
34
|
-
I18n.load_path = [PL]
|
35
|
-
expect(@loader.load(RU)).to eq(
|
36
|
-
'users' => R18n::Typed.new(
|
37
|
-
'pl',
|
38
|
-
0 => 'Ноль',
|
39
|
-
1 => 'Один',
|
40
|
-
2 => 'Несколько',
|
41
|
-
'n' => 'Много'
|
42
|
-
)
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'reloads translations on load_path changes' do
|
47
|
-
I18n.load_path << OTHER
|
48
|
-
expect(@loader.load(RU)).to eq(
|
49
|
-
'one' => 'Один',
|
50
|
-
'two' => 'Два',
|
51
|
-
'three' => 'Три'
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'changes hash on load_path changes' do
|
56
|
-
before = @loader.hash
|
57
|
-
I18n.load_path << OTHER
|
58
|
-
expect(@loader.hash).not_to eq before
|
59
|
-
end
|
60
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require 'i18n'
|
5
|
-
require 'active_support'
|
6
|
-
|
7
|
-
I18n.enforce_available_locales = true
|
8
|
-
|
9
|
-
require_relative '../lib/r18n-rails-api'
|
10
|
-
|
11
|
-
EN = R18n.locale(:en)
|
12
|
-
RU = R18n.locale(:ru)
|
13
|
-
DECH = R18n.locale(:'de-CH')
|
14
|
-
|
15
|
-
GENERAL = Dir.glob(File.join(__dir__, 'data', 'general', '*'))
|
16
|
-
SIMPLE = Dir.glob(File.join(__dir__, 'data', 'simple', '*'))
|
17
|
-
OTHER = Dir.glob(File.join(__dir__, 'data', 'other', '*'))
|
18
|
-
PL = Dir.glob(File.join(__dir__, 'data', 'pl', '*'))
|