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