sinatra-r18n 3.1.1 → 5.0.2

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