r18n-core 3.0.5 → 3.1.1

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: 868e777a8f94095134b7addd1c4f5eea84bd30c3733b6d347b9332a52dcc87a2
4
- data.tar.gz: 87772a5cee32a904f30c2fab64be0c787f713fb528caeff493c870428133909c
3
+ metadata.gz: 01fc9db07f902211f29b89542f1b6aacb393c85efa4ef48e0750b24b9dbbc94e
4
+ data.tar.gz: cf6c8d62cb4d1447bfd9b0f34fb78dde6e35ebe7ed71e3e7fb94132bb0593278
5
5
  SHA512:
6
- metadata.gz: f8558a75174109289ffc43c4ebdbbbc20651069fcc3c4cf4a59398ab318b35bb9030f206220882951a3705c14804ac724faee9cf3f7582c0940657f1864994e4
7
- data.tar.gz: 17dcefed65081193ec2605a6ed619f36dc3ef1ee390e19b5b9f2931b26508ae7d397612a85ee6b0410d73304e31665a4920716068e346f8b5d539846fde334fe
6
+ metadata.gz: de9b44856131d6d52daa7348033a6af6285bfe740f0a064ba24540071a2798a0d025976458112e6465d2386e2bfa61f5a11e40038dee4fcb77778a6103923ce0
7
+ data.tar.gz: 7be0bf1ccf786dd09132779852cc86bcc4d5b620ce5de7d78640a04c87e33737a0a0cb98fc5e2b85faaa2e603d5592328446d8960ef32404332109561446614e
data/README.md CHANGED
@@ -281,6 +281,25 @@ alarm: !!textile
281
281
  t.alarm #=> "<p>It will delete <em>all</em> users!</p>"
282
282
  ```
283
283
 
284
+ #### Named variables
285
+
286
+ After enabling built-in `named_variables` filter, you can use named variables
287
+ in all translations:
288
+
289
+ ```yaml
290
+ greeting: "Hi, %{name}"
291
+ users: !!pl
292
+ 1: One user
293
+ n: {{count}} users
294
+ ```
295
+
296
+ ```ruby
297
+ Filters.on(:named_variables)
298
+
299
+ t.greeting(name: 'John') #=> "Hi, John"
300
+ t.users(count: 5) #=> "5 users"
301
+ ```
302
+
284
303
  ### Localization
285
304
 
286
305
  You can print numbers and floats according to the rules of the user locale:
@@ -262,6 +262,22 @@ module R18n
262
262
  end
263
263
  end
264
264
 
265
+ Filters.add(String, :named_variables) do |content, config, params|
266
+ if params.is_a? Hash
267
+ content = content.clone
268
+ params.each_pair do |name, value|
269
+ value = config[:locale].localize(value)
270
+ if defined? ActiveSupport::SafeBuffer
271
+ value = ActiveSupport::SafeBuffer.new + value
272
+ end
273
+ content.gsub! "%{#{name}}", value
274
+ content.gsub! "{{#{name}}}", value
275
+ end
276
+ end
277
+ content
278
+ end
279
+ Filters.off(:named_variables)
280
+
265
281
  Filters.add(Untranslated, :untranslated) do |_v, _c, translated, untranslated|
266
282
  "#{translated}[#{untranslated}]"
267
283
  end
@@ -170,12 +170,13 @@ module R18n
170
170
 
171
171
  type = obj.is_a?(Date) && !obj.is_a?(DateTime) ? 'date' : 'time'
172
172
  format ||= :standard
173
+ format_method_name = "format_#{type}_#{format}"
173
174
 
174
- unless %i[human full standard].include? format
175
+ unless respond_to? format_method_name
175
176
  raise ArgumentError, "Unknown time formatter #{format}"
176
177
  end
177
178
 
178
- send "format_#{type}_#{format}", obj, *params
179
+ send format_method_name, obj, *params
179
180
  else
180
181
  obj.to_s
181
182
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version of R18n Core
4
4
  module R18n
5
- VERSION = '3.0.5'.freeze unless defined? R18n::VERSION
5
+ VERSION = '3.1.1'.freeze unless defined? R18n::VERSION
6
6
  end
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.files = `git ls-files`.split("\n")
21
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.extra_rdoc_files = ['README.md', 'LICENSE', 'ChangeLog.md']
22
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
23
23
  s.require_path = 'lib'
24
24
 
25
25
  s.author = 'Andrey Sitnik'
26
26
  s.email = 'andrey@sitnik.ru'
27
27
  s.homepage = 'https://github.com/ai/r18n'
28
- s.license = 'LGPL-3'
28
+ s.license = 'LGPL-3.0'
29
29
  end
@@ -190,6 +190,21 @@ describe R18n::Filters do
190
190
  )
191
191
  end
192
192
 
193
+ it 'interpolates named variables' do
194
+ R18n::Filters.off(:named_variables)
195
+ expect(@i18n.echo(value: 'R18n')).to eq 'Value is %{value}'
196
+
197
+ R18n::Filters.on(:named_variables)
198
+ expect(@i18n.echo(value: 'R18n')).to eq 'Value is R18n'
199
+ expect(@i18n.echo(value: -5.5)).to eq 'Value is −5.5'
200
+ expect(@i18n.echo(value: 5000)).to eq 'Value is 5,000'
201
+ expect(@i18n.echo(value: '<b>')).to eq 'Value is <b>'
202
+ expect(@i18n.echo).to eq 'Value is %{value}'
203
+
204
+ expect(@i18n.echo2(value: 'R18n')).to eq 'Value2 is R18n'
205
+ expect(@i18n.echo2).to eq 'Value2 is {{value}}'
206
+ end
207
+
193
208
  it 'formats untranslated' do
194
209
  expect(@i18n.in.not.to_s).to eq('in.[not]')
195
210
  expect(@i18n.in.not.to_str).to eq('in.[not]')
@@ -292,16 +307,18 @@ describe R18n::Filters do
292
307
 
293
308
  it 'escapes variables if ActiveSupport is loaded' do
294
309
  expect(@i18n.escape_params('<br>')).to eq('<b><br></b>')
295
- require 'active_support'
296
- expect(@i18n.escape_params('<br>')).to eq('<b>&lt;br&gt;</b>')
297
- end
298
310
 
299
- it 'uses SafeBuffer if it is loaded' do
300
311
  require 'active_support'
301
312
 
313
+ expect(@i18n.escape_params('<br>')).to eq('<b>&lt;br&gt;</b>')
314
+
302
315
  R18n::Filters.on(:global_escape_html)
303
316
  @i18n.reload!
304
317
 
305
318
  expect(@i18n.greater('<b>'.html_safe)).to eq('1 &lt; 2 is <b>')
319
+
320
+ R18n::Filters.on(:named_variables)
321
+
322
+ expect(@i18n.echo(value: '<b>')).to eq 'Value is &lt;b&gt;'
306
323
  end
307
324
  end
@@ -175,6 +175,16 @@ describe R18n::Locale do
175
175
  expect(@ru.localize(Time.at(0), :human)).to eq(Time.at(0).to_s)
176
176
  end
177
177
 
178
+ it 'localizes date in custom formatter if exists' do
179
+ allow(@en).to receive(:format_date_my_own_way) do |date|
180
+ date == Date.today ? 'DOOMSDAY!' : 'Just another day'
181
+ end
182
+
183
+ expect(@en.localize(Date.today, :my_own_way)).to eq('DOOMSDAY!')
184
+ expect(@en.localize(Date.today + 1, :my_own_way)).to eq('Just another day')
185
+ expect(@en.localize(Date.today - 1, :my_own_way)).to eq('Just another day')
186
+ end
187
+
178
188
  it 'raises error on unknown formatter' do
179
189
  expect do
180
190
  @ru.localize(Time.at(0).utc, R18n::I18n.new('ru'), :unknown)
@@ -39,6 +39,9 @@ textile:
39
39
  simple: !!textile _Hi!_
40
40
  html: !!textile _Hi!_<br />
41
41
 
42
+ echo: Value is %{value}
43
+ echo2: Value2 is {{value}}
44
+
42
45
  boolean:
43
46
  true: Boolean is true
44
47
  false: Boolean is false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r18n-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Sitnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-19 00:00:00.000000000 Z
11
+ date: 2018-08-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  R18n is a i18n tool to translate your Ruby application.
@@ -22,10 +22,8 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.md
24
24
  - LICENSE
25
- - ChangeLog.md
26
25
  files:
27
26
  - ".rspec"
28
- - ChangeLog.md
29
27
  - LICENSE
30
28
  - README.md
31
29
  - Rakefile
@@ -156,7 +154,7 @@ files:
156
154
  - spec/yaml_loader_spec.rb
157
155
  homepage: https://github.com/ai/r18n
158
156
  licenses:
159
- - LGPL-3
157
+ - LGPL-3.0
160
158
  metadata: {}
161
159
  post_install_message:
162
160
  rdoc_options: []
@@ -1,323 +0,0 @@
1
- # Change Log
2
-
3
- ## 3.0.5 (ب)
4
- * Fix Farsi locale name (by @iriman).
5
-
6
- ## 3.0.4 (𐤀)
7
- * Fix `Translated` compatibility with `Hash` (by Alexander Popov).
8
-
9
- ## 3.0.3 (〥)
10
- * Fix missed filters in `Untranslted` initialization (by Alexander Popov).
11
-
12
- ## 3.0.2 (Ё)
13
- * Fix `Untranslted.to_s` (by Patrik Rak).
14
-
15
- ## 3.0.1 (Brooklyn)
16
- * Fix `no` locale deprecation warning.
17
-
18
- ## 3.0 (New York)
19
- * Deprecate `no` locale, use `nb` instead (by Alexander Popov).
20
- * Remove unsafe `!!proc` filter.
21
- * Reduce `eval` calls (by Alexander Popov).
22
-
23
- ## 2.2 (La Habana)
24
- * Change date format in `en` locale to `YYYY-MM-DD` (by Alexander Popov).
25
- * Add `TranslatedString#as_json` for ActiveSupport compatibility (by Tim Craft).
26
- * Fix `TranslatedString#html_safe?` behaviour (by Tim Craft).
27
- * Fix unsupported `LANG` environment (by Chris Poirier).
28
- * Fix `Locale#localize` method for `DateTime` objects (by Alexander Popov).
29
-
30
- ## 2.1.8 (Ѣ)
31
- * Fix `true` and `false` keys support (by Alexander Popov).
32
-
33
- ## 2.1.7 (Sewe)
34
- * Add Afrikaans locale (by Llewellyn van der Merwe).
35
-
36
- ## 2.1.6 (Berlin)
37
- * Better `TranslatedString` → `String` converting (by Patrik Rak).
38
- * Add Ruby on Rails 5 support.
39
-
40
- ## 2.1.5 (මාතර)
41
- * Fix Ruby 2.4 support (by Alexander Popov)
42
-
43
- ## 2.1.4 (Bakı)
44
- * Add Azerbaijani locale (by Adil Aliyev).
45
-
46
- ## 2.1.3 (Seoul)
47
- * Add Korean locale (by Patrick Cheng).
48
-
49
- ## 2.1.2 (Wien)
50
- * Fix Ruby 2.3 support.
51
-
52
- ## 2.1.1 (Barcelona)
53
- * Better sanity check for Accept-Language header (by Viktors Rotanovs).
54
-
55
- ## 2.1 (Một)
56
- * Add Vietnamese locale (by Nguyễn Văn Được).
57
- * Add Persian locale.
58
- * Allow to change date/time order in locales.
59
- * Fix pluralization in locales without plural forms.
60
- * Fix Mongolian base translations.
61
-
62
- ## 2.0.4 (Ikkuna)
63
- * Fix Windows support (by janahanEDH).
64
-
65
- ## 2.0.3 (Hévíz)
66
- * Fix Thai locale (by Kasima Tharnpipitchai).
67
-
68
- ## 2.0.2 (Budapest)
69
- * Fix array support in translations.
70
- * Fix Rails support for dialect locales.
71
-
72
- ## 2.0.1 (Amsterdam)
73
- * Fix Dutch locale.
74
-
75
- ## 2.0.0 (Москва)
76
- * Remove Ruby 1.8 and 1.9 support.
77
- * Add JRuby 9000 support.
78
-
79
- ### 1.1.11 (São Paulo)
80
- * Allow to set Proc as `default` option in Rails I18n backend.
81
-
82
- ### 1.1.10 (十)
83
- * Fix Esperanto locale by Larry Gilbert.
84
- * Fix Chinese locale (by 刘当一).
85
-
86
- ### 1.1.9 (Не знайдено)
87
- * Fix Rails 4.0.4 support. Prevent loop on `enforce_available_locales`.
88
-
89
- ### 1.1.8 (Osam)
90
- * Add Croatian locale (by Dino Kovač).
91
- * Add Serbian latin locale (by Dino Kovač).
92
-
93
- ### 1.1.7 (Tujuh)
94
- * Return `nil` on untranslated in models with Translated.
95
- * Add `transliterate` method to I18n backend.
96
- * Add Indonesian locale (by Guntur Akhmad).
97
-
98
- ### 1.1.6 (Vitebsk)
99
- * Return `TranslatedString` after global String filters.
100
- * Fix path in global String filters.
101
-
102
- ### 1.1.5 (Hilo)
103
- * Fix Sinatra plugin under multithreaded web-server (by Viktors Rotanovs).
104
- * Fix BigDecimal localizing (by François Beausoleil).
105
- * Add American American Spanish locale (by renemarcelo).
106
-
107
- ### 1.1.4 (Bokmål)
108
- * Add Norwegian “no” locale as gateway to Bokmål or Nynorsk.
109
- * Fix Norwegian Bokmål locale code.
110
- * Fix hungarian time format (Kővágó Zoltán).
111
-
112
- ### 1.1.3 (Saint Petersburg)
113
- * Fix memory leak from cache key missmatch in Rails plugin (by silentshade).
114
-
115
- ### 1.1.2 (Marshal)
116
- * Fix translation and untranslated marshalizing (by silentshade).
117
- * Allow to compare untranslated strings.
118
- * Fix untranslated strings output in tests.
119
-
120
- ### 1.1.1 (Dunhuang)
121
- * Don’t change YAML parser in Ruby 1.9.
122
- * Allow to change locale by argument in R18n Rails backend.
123
- * Set also Rails I18n locale in Rails autodetect filter.
124
- * Fix caching with custom filters (by Anton Onyshchenko).
125
- * Fix translation variables with `%1` text inside (by Taras Kunch).
126
- * Fix Latvian locale (by Aleksandrs Ļedovskis).
127
-
128
- ### 1.1.0 (Leipzig)
129
- * A lot of fixes in Rails I18n compatibility (thanks for Stephan Schubert).
130
- * Return Untranslted, when user try to call another translation key on
131
- already translated string.
132
- * Add `Translation#to_hash` to get raw translation.
133
- * Add `Translation#inspect` to easy debug.
134
- * Return translation, when pluralization filter didn’t get count.
135
- * Set R18n backend on Rails plugin init, to use it in console.
136
- * Allow to use Integer in translation keys.
137
-
138
- ### 1.0.1 (Phuket Town)
139
- * Fix translation reloading in Rails and Sinatra.
140
- * Use global R18n settings for Sinatra extension.
141
- * Allow to override desktop autodetect by LANG environment on all platforms.
142
- * Add support for JRuby in 1.9 mode.
143
- * Rename `R18n.reset` to `R18n.reset!` and add `R18n.clear_cache!`.
144
- * Fix Sinatra with loaded ActiveSupport.
145
- * Add Mongolian locale (by Elias Klughammer).
146
-
147
- ### 1.0.0 (Bangkok)
148
- * Add `R18n.default_places`.
149
- * Rails SafeBuffer support.
150
- * Allow in Rails app to put filters to `app/i18n` reload them in development.
151
- * Move `R18n::I18n.available_locales` to `R18n.available_locales`.
152
- * Rename `_keys` to `translation_keys`.
153
- * Use Kramdown instead of Maruku for Markdown.
154
- * Allow to use R18n for Rails without mailer.
155
- * Allow to overwrite I18n object for models.
156
- * Autoload R18n::Translated.
157
- * Set default locale to R18n on Rails start to easy use in Rails console.
158
- * Use env language in Rails console.
159
- * Mark untranslated part as red in Rails console.
160
- * Allow to temporary change locale by `R18n.change`.
161
- * Add `R18n.locale` shortcut.
162
- * Allow return from setter block locale code, instead of I18n object.
163
- * Allow to set custom filters for I18n object.
164
- * Add Galician locale (by Eduard Giménez).
165
- * Add Traditional Chinese and Simplified Chinese (by Francis Chong).
166
- * Fix Norsk locale (by Peter Haza).
167
-
168
- ### 0.4.14 (üç)
169
- * Fix support for Ruby 1.9.3.
170
- * Added Turkish locale (by Ahmet Özkaya).
171
- * Fix Swedish locale (by Pär Wieslander).
172
-
173
- ### 0.4.13 (Sti)
174
- * Fix Pathname to String error in r18n-desktop.
175
- * Add Norwegian locale (by Oddmund Strømme).
176
-
177
- ### 0.4.12 (Шлях)
178
- * Fix Pathname to String convertion error.
179
- * Fix model translation for non-ActiveRecord (by Szymon Przybył).
180
- * Add Ukrainian locale (by Ярослав Руденок).
181
-
182
- ### 0.4.11 (Nancy)
183
- * Support for Sinatra 1.3.
184
- * Fix JRuby support by Paul Walker.
185
- * Add R18n helpers to Rails mailer by Alexey Medvedev.
186
-
187
- ### 0.4.10 (Kvantum)
188
- * Add R18n.set(locales, places), R18n.t and R18n.l shortcuts.
189
- * Convert float to number on pluralization.
190
- * Fix loading empty translation file.
191
- * Add Portuguese locale.
192
- * Add Dutch locale (by Sander Heilbron).
193
- * Add Swedish locale (by Magnus Hörberg).
194
-
195
- ### 0.4.9 (Kazan)
196
- * Add support for Psych YAML parser (thanks for Ravil Bayramgalin).
197
- * Fix ActiveRecord support in Translated.
198
- * Fix Translated to return non-string values.
199
- * Fix human time localization.
200
- * Add Bulgarian locale (by Mitko Kostov).
201
- * Add Australian English locale (by Dave Sag).
202
-
203
- ### 0.4.8 (En ni to)
204
- * Fix support for Ruby 1.9.2.
205
- * Fix caching issue (by Viktors Rotanovs).
206
- * Add Danish locale (by Hans Czajkowski Jørgensen)
207
- * Fix Italian locale (by Viktors Rotanovs).
208
- * Move untranslated filters with html highlight to r18n-core.
209
-
210
- ### 0.4.7.1 (Kyū)
211
- * Fix Japanese locale in Ruby 1.9.1.
212
-
213
- ### 0.4.7 (Mado)
214
- * Fix autodetect locale in Windows and Ruby 1.9.1 (by Marvin Gülker).
215
- * Fix autodetect locale in JRuby (by Kővágó, Zoltán).
216
- * Fix human time format on 60 minutes.
217
- * Add Hungarian locale (by Kővágó, Zoltán).
218
- * Add Japanese locale (by hryk).
219
- * Fix Polish locale (by Piotr Szotkowski).
220
-
221
- ### 0.4.6 (Trinity)
222
- * Add support for new interpolation syntax in Rails 3.
223
- * Add Catalian locale (by Jordi Romero).
224
- * Add Finish locale (by Laura Guillén).
225
- * Add British locale (by JP Hastings-Spital).
226
- * Add Latvian locale (by Iļja Ketris).
227
- * Fix Spanish (by Jordi Romero), German, French, Esperanto (by Iļja Ketris) and
228
- Polish locales.
229
- * Fix documentation (by Iļja Ketris and felix).
230
- * Remove RubyGems from plugins requires.
231
-
232
- ### 0.4.5 (Annual)
233
- * Filters for several types.
234
- * Global HTML escaping run before Markdown and Textile formatting.
235
- * Fix active filters after passive filters.
236
- * Fix human time formatting for dates with same month days.
237
-
238
- ### 0.4.4 (Frank)
239
- * Use before filter to lazy set I18n object in Sinatra extension.
240
- * Set I18n object to thread (by Simon Hafner).
241
- * Add to l Rails helper R18n syntax.
242
- * Add common helpers.
243
- * Clear cache in R18n.reset.
244
- * Clean up code and fix bug (by Akzhan Abdulin).
245
- * Add Thai locale (by Felix Hanley).
246
-
247
- ### 0.4.3 (Flange)
248
- * Add R18n style methods to Rails controllers.
249
- * Fix for non-string translations in Rails I18n.
250
- * Use default locale from Rails I18n config.
251
- * Load translations recursively.
252
- * Add Slovak locale (by Ahmed Al Hafoudh)
253
-
254
- ### 0.4.2 (EMS)
255
- * Fixes for Ruby 1.8.6 (by Akzhan Abdulin).
256
- * Add method to get translation keys.
257
-
258
- ### 0.4.1 (Lazy Boole)
259
- * Add passive filters.
260
- * Receive filter position as option Hash.
261
- * Fix base translations (by Pavel Kunc).
262
-
263
- ### 0.4 (D-Day)
264
- * Rails I18n compatibility.
265
- * Rewrite a lot of core code to fast and cleanup version.
266
- * Custom translation loaders.
267
- * Add reload! method to I18n.
268
- * Add t and l helpers to Sinatra and desktop plugins.
269
- * Syntax sugar for default values.
270
- * Named variables.
271
- * New locale API.
272
- * Change API for extension translations.
273
-
274
- ### 0.3.2 (Pidgin)
275
- * Print path of untranslated string by filters.
276
- * Add Italian locale (by Guido De Rosa).
277
- * Fix Polish locale (by Adrian Pacała).
278
- * Fix American English locale (by Max Aller).
279
-
280
- ### 0.3.1 (Yield)
281
- * Add Chinese locale (by Ilia Zayats).
282
- * Add Spanish locale (by Andre O Moura).
283
- * Add Brazilian Portuguese locale (by Andre O Moura).
284
- * Remove RubyGems requires.
285
-
286
- ### 0.3 (Vladivostok)
287
- * Translated mixin to add i18n support to model or any other class.
288
- * New cool time formatters.
289
- * Filters for translations.
290
- * Add filters to escape HTML, Markdown and Textile syntax.
291
- * Pluralization and variables is now filters and can be replaced.
292
- * I18n#locales now contain all detected locales, used to load translations,
293
- instead of just received from user.
294
- * Bugfix in locale code case.
295
- * Add Czech locale (by Josef Pospíšil).
296
-
297
- ### 0.2.3 (Shanghai eclipse)
298
- * R18n will return path string if translation isn’t exists.
299
- * Add UnsupportedLocale class for locale without information file.
300
- * Load absent locale information from default locale.
301
- * Add Polish locale (by Tymon Tobolski).
302
-
303
- ### 0.2.2 (Clone Wars)
304
- * Localize numbers in pluralization.
305
- * Bugfix in translation variables.
306
-
307
- ### 0.2.1 (Neun)
308
- * Ruby 1.9 compatibility.
309
- * Add German locale (by Benjamin Meichsner).
310
-
311
- ### 0.2 (Freedom of Language)
312
- * Locale class can be extended for special language (for example, Indian locale
313
- may has another digits grouping).
314
- * Load translations from several dirs.
315
- * Add French locale.
316
- * Add Kazakh locale.
317
-
318
- ### 0.1.1 (Saluto)
319
- * Loading i18n object without translations.
320
- * Add output for standalone month name.
321
- * Don’t call procedures from translations if it isn’t secure.
322
- * Add Esperanto locale.
323
- * English locale now contain UK date standards.