-
Notifications
You must be signed in to change notification settings - Fork 393
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
RFC: Context + hash based message id #1360
RFC: Context + hash based message id #1360
Comments
@thekip if I understand correctly, these hashes will appear in the localization files like PO or JSON as keys, right? |
In po files everything would be the same, because po files support context natively. For json formats it is correct. That's exactly as it works in other most popular libraries, such as https://formatjs.io/docs/getting-started/message-extraction |
Interesting fact, Tomáš Ehrlich, original author of the library, mentioned this issue and solution proposed in this RFC in his talk at React Conf 2018, but looks like this was never implemented. |
You're right, I never get to implementing this idea. It seems possible:
At the time I was even thinking about using js variables instead of object keys. That way the minification is handled by bundler plus it might even remove unused messages with dead code elimination, but I guess that too far stretched. |
I think generating a hash based i with fixed (short) length would be more than enough. All libraries which involve compilation into process uses the same approach (formatjs, angular's localize) |
Yes double yes, I'm so excited by this feature! |
Current lingui implementation has a flaw: you have your original message in the bundle at least 2 times + 1 translation.
For a line "Hello world" you would have one in the source code as id in i18n call:
Another one as key in the message catalog and then a translation itself:
Strings could be very long, not just a couple words, so this may bring more kb to the bundle.
If you use context for the string it would be even more kilobytes because for each msg which should have a context you would have context explicitly written in the bundle + in the msg catalog.
A much better option would be generating a "stable" ID based on the msg + context as hash with fixed length.
So internal structure would look like
And lookups in runtime would be much simpler.
Hash would be calculated at build time by macros. So macros instead of
Would generate:
The context feature would affect ONLY messageid generation, and thus would only be supported when using macro. For the non-macro users using context has no sense because they provide a messageid manually.
Default message and context would be stripped from runtime code and replaced to the ID generated in compile time.
The text was updated successfully, but these errors were encountered: