-
Notifications
You must be signed in to change notification settings - Fork 386
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
feat: msgctxt support #1094
feat: msgctxt support #1094
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/lingui-js/js-lingui/Fo95hJ74iAUVNaZpH8Hm7G7nGaCz |
Codecov Report
@@ Coverage Diff @@
## main #1094 +/- ##
==========================================
- Coverage 81.88% 81.49% -0.39%
==========================================
Files 56 56
Lines 1678 1724 +46
Branches 458 474 +16
==========================================
+ Hits 1374 1405 +31
- Misses 182 189 +7
- Partials 122 130 +8
Continue to review full report at Codecov.
|
Hey @semoal think you could take a look when you have the chance? |
@nakkamarra this looks great! @semoal is this something that could make it in a future release? We have a few strings in our application that we have issues with and our current workaround (custom msgids) isn't the greatest way to handle this. Let me know if we can help :) |
@jeroenvisser101 thanks, I'm no longer working with lingui and this PR is probably a bit outdated now, but if you wanted to grab this branch and merge the main branch and see if there are any conflicts / changes that need to be made I think it'd be a good way to see this feature make it over the finish line. |
It's cool @nakkamarra I reviewed it and look fine to me, let's release a new version tomorrow with this feature and if @jeroenvisser101 finds some issues feel free to open an issue and I'll solve them asap :) |
After so much time, finally this is released guys.. Sorry for the delay I've been lately so busy .. |
As described as part of: #856
My decision here was to use
context
/msgctxt
as a way to "sub-key" a given key, which I feel lines up more with the original gettext implmentation/intention of context. So if we had a catalog like so:the addition of context could be modeled like so:
where a given context string acts as the key of another sub-catalog of translations. This allows one to add multiple translations for a given ID / string by using different contexts. To pull out translations, one would reference
this.messages[context][id]
instead ofthis.messages[id]
in the case that context was defined for a given ID.On top of that, I think this is actually pretty trivial to support for many of lingui's current formats (
po
,po-gettext
,minimal
, andraw
), since we're just creating sub-objects and serializing / deserializing them. As far as CSV is concerned, I think there'd need to be a bit of extra work, but it could be possible to apply something similar to what we're doing with JSON (imagine instead of each row beingkey, translation
you havecontext, key, translation
and work with that)There's the caveat that this does not abstract
msgid
s and solve the shrinking of IDs in catalogs, one of the upsides to @Bertg's approach to this problem.I'd say this is about 90% of the way there, but I'd love to get some feedback and thoughts around this approach, particularly around this chunk which could be refactored to be much cleaner: https://github.com/lingui/js-lingui/compare/main...nakkamarra:msgctx-support?expand=1#diff-9317c05f72203559bc3788fb80d76d19f38b457e50c35c430463d964574eec90R27-R80
@semoal @tricoder42 @Bertg