Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pluralization behavior for KeyValue backend with subtrees disabled #419

Merged
merged 2 commits into from
Jul 15, 2018

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Jul 10, 2018

This PR includes a fix making the pluralization behavior for the KeyValue backend with subtrees disabled conform more closely to the behavior of the default Simple backend, as well as the KeyValue backend with subtrees enabled.

My use-case for this PR is migrating an existing application from a Simple to a KeyValue backend with subtrees disabled for performance, where the existing application depends on specific fallback/pluralization semantics to run without further modification.

The simple code change to key_value.rb fixes the following two errors, which I've reproduced in the added tests:

  1) Error:
 I18nBackendKeyValueTest#test_subtrees_disabled:_Returns_fallback_default_given_missing_pluralization_data:
NoMethodError: undefined method `[]' for nil:NilClass
    [Code]/i18n/lib/i18n/backend/key_value.rb:131:in `pluralize'
    [Code]/i18n/lib/i18n/backend/base.rb:48:in `translate'
    [Code]/i18n/lib/i18n/backend/fallbacks.rb:48:in `block (2 levels) in translate'
    [Code]/i18n/lib/i18n/backend/fallbacks.rb:47:in `catch'
    [Code]/i18n/lib/i18n/backend/fallbacks.rb:47:in `block in translate'
    [Code]/i18n/lib/i18n/backend/fallbacks.rb:45:in `each'
    [Code]/i18n/lib/i18n/backend/fallbacks.rb:45:in `translate'
    [Code]/i18n/lib/i18n.rb:185:in `block in translate'
    [Code]/i18n/lib/i18n.rb:181:in `catch'
    [Code]/i18n/lib/i18n.rb:181:in `translate'
    [Code]/i18n/test/backend/key_value_test.rb:81:in `block in <class:I18nBackendKeyValueTest>'

  2) Error:
I18nBackendKeyValueTest#test_subtrees_disabled:_returns_localized_string_given_missing_pluralization_data:
TypeError: no implicit conversion of Symbol into Integer
    [Code]/i18n/lib/i18n/backend/key_value.rb:131:in `[]'
    [Code]/i18n/lib/i18n/backend/key_value.rb:131:in `pluralize'
    [Code]/i18n/lib/i18n/backend/base.rb:48:in `translate'
    [Code]/i18n/lib/i18n.rb:185:in `block in translate'
    [Code]/i18n/lib/i18n.rb:181:in `catch'
    [Code]/i18n/lib/i18n.rb:181:in `translate'
    [Code]/i18n/test/backend/key_value_test.rb:69:in `block in <class:I18nBackendKeyValueTest>'

@radar
Copy link
Collaborator

radar commented Jul 15, 2018

Thanks @wjordan. This LGTM. I'll merge it now and release it in a new i18n release later today.

@radar radar merged commit 6870a98 into ruby-i18n:master Jul 15, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants