From 7559fef756c20ba200e60276a85e071474f3cbbf Mon Sep 17 00:00:00 2001 From: tom-lord Date: Sun, 24 Mar 2024 00:21:23 +0000 Subject: [PATCH] More examples documented --- lib/i18n.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/i18n.rb b/lib/i18n.rb index 2a30431c..c0532d1f 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -233,18 +233,23 @@ def translate!(key, **options) # Returns an array of interpolation keys for the given translation key # + # *Examples* + # # Suppose we have the following: # I18n.t 'example.zero' == 'Zero interpolations' # I18n.t 'example.one' == 'One interpolation %{foo}' # I18n.t 'example.two' == 'Two interpolations %{foo} %{bar}' + # I18n.t 'example.three' == ['One %{foo}', 'Two %{bar}', 'Three %{baz}'] # I18n.t 'example.one', locale: :other == 'One interpolation %{baz} %{bar}' # # Then we can expect the following results: # I18n.interpolation_keys('example.zero') #=> [] # I18n.interpolation_keys('example.one') #=> ['foo'] # I18n.interpolation_keys('example.two') #=> ['foo', 'bar'] + # I18n.interpolation_keys('example.three') #=> ['foo', 'bar', 'baz'] # I18n.interpolation_keys('one', scope: 'example', locale: :other) #=> ['baz'] # I18n.interpolation_keys('does-not-exist') #=> [] + # I18n.interpolation_keys('example') #=> [] def interpolation_keys(key, **options) raise I18n::ArgumentError if !key.is_a?(String) || key.empty?