Splitting translations?

I’m looking at migrating to react_on_rails and I’m trying to better understand what it provides as it relates to I18n. If I understand the code for rake react_on_rails:locale properly, it looks like it puts all of the translations into a single file. Is that accurate?

Is there any way to split translations up through the rake task, both by locale and by section of the website? As an example, in my translations, I may want all of the strings that relates to the LoginComponent, which would be children of the “login” key in the translations, to be in its own file (one for each language). I’d load the translation for those translations only when I use the LoginComponent and nowhere else. Is that possible?

If not, is there a recommended way to split up the translation file so they don’t all have to be loaded at once?

Hi @wwahammy,

It sounds like what you want is https://loadable-components.com/.

We’ve got a really good setup for that for React on Rails Pro.

If you don’t need to reuse the string in both the Rails app and the front-end, I’d recommend using react-intl directly and depending on tree-shaking and code-splitting for optimizing the bundle sizes.

If you think React on Rails Pro might be a good fit for your project, please book a time with me.

Thanks,

Justin

Thanks for the feedback.

I’d tend to prefer keeping the translations in a single place but I supposed they could be split into front-end and backend translations.

Unfortunately React on Rails Pro isn’t feasible for our project. We’re licensed under the AGPL so we can’t include code which is licensed under a proprietary license.

As a sense of what I was hoping to find was something like the ability to split translations like the i18n-js gem.

@wwahammy the license is not a big issue. We can work around that. The key thing about React on Rails Pro is getting 1 hour per month of personal consulting to help you achieve your goals efficiently.

I see the source code:

1 Like

This discussion seems to be worth a call. I’ll schedule one and we can talk more there and see what makes sense.