Hello everyone, I have ever so quietly opened a di...
# contributing
j
Hello everyone, I have ever so quietly opened a discussion concerning how we are going to handle localization/internationalization (i18n) in the new Backoffice: https://github.com/umbraco/Umbraco.CMS.Backoffice/discussions/818 As you can see, we have already begun some proof-of-concept work. Feel free to weigh in with any thoughts/opinions to guide us in the right direction 🎉
This might be something for you, @Kevin Jump. It is directly related to our little airport discussion 😉
The initial pull request has been updated with very concrete examples of usage in the description as well as in the code and storybook: https://github.com/umbraco/Umbraco.CMS.Backoffice/pull/817
j
A discussion...?
So there's more to be said than "Just use https://www.i18next.com" ?
😉
j
Do you want the short or the extended answer for that? 😉
i18next is a good library - it's huuuge though. But the extension API is built in a way so that you may use that (or anything else) in your extensions if you have a need for it. In migrating the backoffice, we are coming from a very simple localization API that just worked with AngularJS with simple token replacement seeing, that all translations were specified on the server, so they had to be a simple format to be carried over from JSON. With the new client, one of the questions is, should we move the translations to the client giving us more flexibility (this is part of the discussion). When yes (we assume we will do this), we have a lot more flexibility allowing us to use a library like i18next. That is not really in question (yet), though if we'll end up with that. The first part of the discussion is more related to how to load translations and to figure out what people actually need.
Working with a POC of translations, I'm inclined to take advantage of the new flexibility quite a bit, but not completely reinventing the wheel. And frankly, I think i18next is too big for us if we look at what we have: a set of UI elements built with Lit that needs to be reactive (because that's how translations worked in the current backoffice) and needs to have simple tokenisation.
I'm looking into a solution that another UI library (Shoelace) came up with, which takes elements from i18next whilst keeping it extremely lightweight: https://github.com/shoelace-style/localize
I'm almost convinced we can solve our needs with that, potentially extending it a little bit for more complex use-cases. Happy to be proven wrong, though, and would be good to get some actual use-cases from the wild brought into the discussion, @Jason.
j
Yeah, I appreciate that argument. For me it's things like pluralisation - I totally take them for granted because i18next just does it, so it's not been a problem for me for 5+ years.
j
Yeah, that and tokens are for me the two big ones when it comes to translatable keys. The current POC is solving it by supporting the token format from the current backoffice:
Hello, %0%, it is %1% today
and pluralization through a factory:
Copy code
somePluralizedKey: (count) => count === 0 ? 'No items' : `${count} items`
Conversely, we will have to keep the language files stored as JavaScript modules rather than JSON to make factories work, but it actually makes it easier to load as well through the client
j
(module all the things)
j
129 commits later and the first part of localization has just been merged 😅 https://github.com/umbraco/Umbraco.CMS.Backoffice/pull/817
j
Nice
2 Views