tater 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tater.rb +35 -0
- data/test/tater_test.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df91dea484a66a6511be668c7738e1970a588f07e3bb71f25687b0472290117d
|
4
|
+
data.tar.gz: 97966c5fa1ff9db5f1c42b1ed98720892646e8dce07e49d24e058c79c9fc08a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e636ba94fb9e1100729adfa4422fa0dc9c0c692bc38915c114a8115c9b711838b448ee49c63653ccdabbbf467c56450aa661240392b61a833061c1e78d1ddd41
|
7
|
+
data.tar.gz: 60bfea0ecab01a4d99fd28789c6cfe9d7bc5f919d430d63eb1f651e58e45166384e244868ccae42246a2668ac4eb6d63964f536d6baee4a7f1b24cfd1953ef8c
|
data/lib/tater.rb
CHANGED
@@ -241,6 +241,41 @@ class Tater
|
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
244
|
+
# Check that there's a key at the given path.
|
245
|
+
#
|
246
|
+
# @param key [String]
|
247
|
+
# The period-separated key path to look within our messages for.
|
248
|
+
# @param options [Hash]
|
249
|
+
# Options to pass to the #lookup method, including locale overrides.
|
250
|
+
#
|
251
|
+
# @option options [Boolean] :cascade
|
252
|
+
# Should this lookup cascade or not? Can override @cascade.
|
253
|
+
# @option options [String] :locale
|
254
|
+
# A specific locale to lookup within. This will take precedence over the
|
255
|
+
# :locales option.
|
256
|
+
# @option options [Array<String>] :locales
|
257
|
+
# An array of locales to look within.
|
258
|
+
#
|
259
|
+
# @return [Boolean]
|
260
|
+
def includes?(key, options = {})
|
261
|
+
cascade_override = options.delete(:cascade)
|
262
|
+
locale_override = options.delete(:locale)
|
263
|
+
locales = options.delete(:locales)
|
264
|
+
|
265
|
+
message =
|
266
|
+
if locale_override || !locales
|
267
|
+
lookup(key, locale_override, cascade_override)
|
268
|
+
else
|
269
|
+
locales.find do |accept|
|
270
|
+
found = lookup(key, accept, cascade_override)
|
271
|
+
|
272
|
+
break found if found
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
!message.nil?
|
277
|
+
end
|
278
|
+
|
244
279
|
# Translate a key path and optional interpolation arguments into a string.
|
245
280
|
# It's effectively a combination of #lookup and #interpolate.
|
246
281
|
#
|
data/test/tater_test.rb
CHANGED
@@ -334,4 +334,29 @@ describe Tater do
|
|
334
334
|
assert cascade.cascades?
|
335
335
|
end
|
336
336
|
end
|
337
|
+
|
338
|
+
describe '#includes?' do
|
339
|
+
let :i18n do
|
340
|
+
Tater.new(path: File.expand_path('test/fixtures'))
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'tells you if you have a translation' do
|
344
|
+
assert i18n.includes?('deep')
|
345
|
+
assert i18n.includes?('deep.key')
|
346
|
+
refute i18n.includes?('deep.nope')
|
347
|
+
refute i18n.includes?('nope')
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'allows overriding the locale' do
|
351
|
+
assert i18n.includes?('french', locale: 'fr')
|
352
|
+
assert i18n.includes?('french', locales: %w[en fr])
|
353
|
+
refute i18n.includes?('french', locales: %w[en])
|
354
|
+
refute i18n.includes?('french')
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'allows cascading' do
|
358
|
+
assert i18n.includes?('cascade.nope.tacos', cascade: true)
|
359
|
+
refute i18n.includes?('cascade.nope.tacos', cascade: false)
|
360
|
+
end
|
361
|
+
end
|
337
362
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Lecklider
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|