SUI-Components / sui

Monorepo for SUI (Simple User Interface) packages.
169 stars 33 forks source link

@s-ui/i18n: Allow monitorize missing translation keys #1731

Open oriolpuig opened 6 months ago

oriolpuig commented 6 months ago

Package

@s-ui/i18n@1

Description

A long time ago, we decided to create the @s-ui/i18n package by forking the node-polyglot npm library instead of wrapping it and getting the new library updates more easily than now. During this time, we have been iterating @s-ui/i18n with some little customizations that now make it more difficult to update the version with the new node-polyglot one.

One of the useful things the node-polyglot library has and we have not, is to allow @s-ui/i18n consumers to use observability tools to track which translation key does not have a translation and find translation issues on the fly. Our library only writes a console.warn to logo it into the client console browser.

Steps to Reproduce

  1. Open your desired browser
  2. Open the browser console
  3. Go to a Fotocasa Ad detail
  4. Filter the console logs by Missing and you will se something like the image bellow
image

Expected behavior: Allow @s-ui/i18n consumers to track when a translation key is missing. We have 3️⃣ approaches:

[!WARNING]
🙏🏻 Please, let me know which approach you like: 1️⃣ , 2️⃣ or 3️⃣ .

Current behavior: When a translation key is missing, a console.warn appears in the browser console.

Additional Information

We can disable the console.warn to avoid printing those warnings on the browser console, but in my opinion is better to empower teams to track and detect the translation issues.

carlosvillu commented 6 months ago

I would say the second approach. But Maybe we can avoid log warnings in production.

marcbenito commented 6 months ago

2️⃣ too

jelowin commented 6 months ago

@oriolpuig, great job, my KUDOS 😍

I agree with you and also with @carlosvillu. I think it's important for the teams to detect translation issues but maybe we could avoid show warnings on production to try to keep the production console cleaner. So I prefer 2️⃣

On the other hand, I understand that you want to avoid using @s-ui/i18n package and only make a wrapper of node-polyglot, am I right?

oriolpuig commented 6 months ago

@jelowin On the other hand, I understand that you want to avoid using @s-ui/i18n package and only make a wrapper of node-polyglot, am I right?

No, we can't override the current version of node-polyglot because our forked version was iterated on our side, si if we override now, we may cause breaking changes in how our tools are using this library.

What I'm proposing is picking this onMissingKey feature from node-polyglot and putting it in our library. But NOT override all.

Thanks for your Kudos!

oriolpuig commented 6 months ago

@carlosvillu I would say the second approach. But Maybe we can avoid log warnings in production.

Yes, actually it's not possible to pass a flag to let us skip this warning, but we can do it with a hack in our portals 👀 by doing this i18n.adapter.instance.allowMissing = true. It's not exactly what we want, but we can achieve it.

Reviewing your proposals, we can add a new prop avoidMissingKeyWarn: true|false to conditionally this from outside. What do you think?

cc/ @jelowin

jordevo commented 6 months ago

excellent contribution, @oriolpuig !

Not sure if I'm missing some context here and perhaps my comment doesn't make sense at all but... if the idea is to capture those error messages from i18n, couldn't we just set up our FE logger so that it also sends or collects console.warn messages? 🤔

oriolpuig commented 6 months ago

Not sure if I'm missing some context here and perhaps it doesn't make sense at all but... if the idea is to capture those error messages from i18n, couldn't we just set up our FE logger so that it also sends or collects console.warn messages? 🤔

Hello @jordevo, thanks for your time!

First of all, as a developer, I think warnings do not make sense to be displayed in production. To get it, we can add a specific flag (for example: avoidMissingKeyWarn: true|false), to skip in production, test CI, or wherever you desire.

But, why do I suggest allowing us to monitor those warnings? I have 2 scenarios in mind:

For those 2 reasons, I suggest to enable this feature and empower teams to monitor uncontrolled translations.

Next Monday we can discuss it in a quick call with some specific demos if you need it, and add here some screenshots to enforce this proposal.

Have a nice weekend! ❤️

jordevo commented 6 months ago

gotcha, @oriolpuig !

I'd even go for a third approach as you kind of point out in your response...

3️⃣ call onMissingKey if configured and allow for console.warn to be configured so that it can be sent or not (ie to be logMissingKey: true on development but logMissingKey: false on production

does it make sense to you?