-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
Implement I18n.eager_load! #469
Conversation
@@ -95,10 +95,19 @@ def available_locales | |||
end | |||
|
|||
def reload! | |||
eager_load! if eager_loaded? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would not call eager_load!
here cause the same problem that you were trying to avoid with our patch? Every time a new I18n path is added we would eager load the files.
I guess this will be fine because you would only call eager_load
after the load_path
are all set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's a trade off. Either reload!
becomes eager once eager_load!
was called once, and you risk wasting compute in reloading the same data multiple times if it's called afterwards.
Or either you don't and then you risk "disabling" eager loading if it's called later.
I think I prefer the former.
@radar 👋 any thoughts on this PR? |
Seems like a sensible fix. Thanks for submitting it! |
@casperisfine Interesting change, thank you! So, in a Rails context, this would be used by adding |
Depending on the amount of translation keys and locales, loading the translation data can be quite slow (~2s in our case).
Because of this, if you are in a production web app context, you do want to trigger the loading during boot time so that the first user to hit that code path won't be slowed down.
Rails has a convention for this, if your namespace respond to
eager_load!
you can simply add it toRails.application.config.eager_load_namespaces
like soRails.application.config.eager_load_namespaces << I18n
.