question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Message files splitting

See original GitHub issue

It seems that one unsolved problem in JavaScript internationalization is automatic splitting of message files, similar to code splitting.

I would like to tackle this problem in v3 and figure out, what API changes we need to make to get it done.

Related issues: https://github.com/lingui/js-lingui/issues/474 https://github.com/lingui/js-lingui/issues/362


Code splitting creates main bundle with loader and then smaller chunks, which can be loaded separately. We know, what modules are included in each chunk (webpack stats data) and we know, what messages are included in each module (origin of message in lingui catalogs). Therefore we can determine what messages are included in each chunk and generate message files for each chunk.

As with code splitting, even locales need to have main bundle, which will include locale specific data like plural rules, date/number formats, etc.

The only question is, how to load chunks of message files.

Webpack handles loading of code chunks automagically (== I have no idea how it works). When we type import "module" and the module isn’t loaded yet, webpack automatically loads the correct chunk.

We can’t do that with locales. Usually, we would write import "locale/en.json", but that would load whole catalog. In fact, we need just import "locale/en.acf422.json", but that filename is generated automatically. We probably need to hook into webpack require and when chunk xyz is loaded, then locale locale/en.xyz.json must be loaded as well.

Finally, the last piece in puzzle - once we have locale chunks loaded automatically, we need to load them into Lingui object.


Notes

While trying to figure out how to load message catalog automatically with code chunk, I discovered next-client-pages-loader from Next.js, which injects some extra code to generated chunk.

We need to either override default webpack require or call another require before/after chunk is loaded, so adding extra code to generted bundle might be related.


Checklist:

  • Generate locale files for each chunk
  • Figure out, how to hook into webpack’s require and load locale chunk along with code chunks
  • Figure out how to feed loaded locale chunks into Lingui

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:22
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
JSteunoucommented, Jun 28, 2021

nooo stale bot please keep it up keep it up 😃

1reaction
tricoder42commented, Oct 30, 2020

@semoal I’ve just created a milestone and added two new possible features.

This issue isn’t trivial because it depends on the framework. I would start with Next.js because it’s closer to me. Just clarify — we’re talking about splitting the compiled catalog, not the source one. We can already split the source catalog using catalogs attribute and, to be hones, even one large source catalog isn’t an issue. The problem is when you send such large catalog to the client, which potentially might explode the bundle size.

It would be great, if we could split the catalog based on generated chunks, but I have no idea how to hook into Webpack. @ScriptedAlchemy mentioned module federation yesterday.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Splitting a single file into multiple messages by length
You can split a file into multiple IBM MQ messages by using the -qs parameter of the fteCreateTransfer command. The file is split...
Read more >
How to Split MBOX File Into Separate Files / Individual ...
It's safe to say that the process of splitting MBOX files is not so difficult if you have the right set of instructions....
Read more >
Splitting target message into multiple files based on source ...
Hi All, I have a SOAP to FILE scenario. Based on a field in source xml, I have to send the data in...
Read more >
Large File Splitting
When datasets are too large to store in message objects, you can use a process design workflow to split the source file into...
Read more >
Split - Apache Camel
Use a Splitter to break out the composite message into a series of individual messages, each containing data related to one item. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found