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

Load faker I18n using custom backend chaining #1389

Conversation

pjohnmeyer
Copy link
Contributor

The previous implementation used I18n.load_path manipulation to
load Faker translations, assuming that the I18n.backend was an
implementation of I18n::Backend::Simple, or something similarly
compatible with load_path and #initialized?. If the user of
the library configured a different backend prior to loading Faker,
this could result in a few possible adverse outcomes:

The new implementation creates a custom backend just for faker,
Faker::I18nBackend. This backend is exactly like the Simple
backend, except that it loads resources only from Faker's locales
folder, ignoring I18n.load_path. An instance of this backend is
then chained together with the existing I18n.backend using
I18n::Backend::Chain. This makes Faker's behavior less intrusive
overall, and eliminates the need for an explicit reload.

Fixes #1078.

The previous implementation used `I18n.load_path` manipulation to
load Faker translations, assuming that the `I18n.backend` was an
implementation of `I18n::Backend::Simple`, or something similarly
compatible with `load_path` and `#initialized?`. If the user of
the library configured a different backend prior to loading Faker,
this could result in a few possible adverse outcomes:

* Faker resources are not _actually_ loaded, leaving Faker unable
  to render those items, or
* As in the case of faker-ruby#1078, a NoMethodError on `#initialized?`

The new implementation creates a custom backend just for faker,
`Faker::I18nBackend`. This backend is exactly like the Simple
backend, except that it loads resources only from Faker's locales
folder, ignoring `I18n.load_path`. An instance of this backend is
then chained together with the existing `I18n.backend` using
`I18n::Backend::Chain`. This makes Faker's behavior less intrusive
overall, and eliminates the need for an explicit reload.

Fixes faker-ruby#1078.
Copy link
Member

@vbrazo vbrazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀

@vbrazo vbrazo merged commit 6903b63 into faker-ruby:master Oct 11, 2018
@vbrazo vbrazo mentioned this pull request Feb 12, 2019
stympy pushed a commit that referenced this pull request Feb 12, 2019
* Rollback i18n PR

* Require helpers
davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
* Load faker I18n using custom backend chaining

The previous implementation used `I18n.load_path` manipulation to
load Faker translations, assuming that the `I18n.backend` was an
implementation of `I18n::Backend::Simple`, or something similarly
compatible with `load_path` and `#initialized?`. If the user of
the library configured a different backend prior to loading Faker,
this could result in a few possible adverse outcomes:

* Faker resources are not _actually_ loaded, leaving Faker unable
  to render those items, or
* As in the case of faker-ruby#1078, a NoMethodError on `#initialized?`

The new implementation creates a custom backend just for faker,
`Faker::I18nBackend`. This backend is exactly like the Simple
backend, except that it loads resources only from Faker's locales
folder, ignoring `I18n.load_path`. An instance of this backend is
then chained together with the existing `I18n.backend` using
`I18n::Backend::Chain`. This makes Faker's behavior less intrusive
overall, and eliminates the need for an explicit reload.

Fixes faker-ruby#1078.

* Minor changes

* Update CHANGELOG.md
davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
* Rollback i18n PR

* Require helpers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants