feat(packages/sui-i18n): Upgrade to node-polyglot v2.5.0 #1739
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With this Pull Request, we have migrated from
[email protected]
to the last one[email protected]
. The main reason to upgrade it is to be able to log the translation issues from outside by providing anonMissingKey
function callback. As you will see in the example section, you could send metrics or trace logs and prevent translation issues in your web app.Before continuing, I suggest you read issue #1731 to learn more about the current problem and how to reproduce it in all of our marketplaces. A quick resume is to avoid those console:
I proposed 3 approaches/scenarios to achieve it:
console.warn
, as is onnode-polyglot
at this lineconsole.warn
at the same time.logMissingKey
to prevent writing theconsole.warn
.Scenario 3️⃣ is the one that people wanted.
So, when you create a
18n
instance:allowMissing
: a boolean to control whether missing keys in at
call are allowed. Iffalse
, by default, a missing key is returned and a warning is issued.onMissingKey
: ifallowMissing
istrue
, and this option is a function, then it will be called instead of the default functionality. Arguments passed to it arekey
,options
, andlocale
. The return of this function will be used as a translation fallback whenpolyglot.t('missing.key')
is called (hint: return the key).logMissingKey
: by default is true to not break the current workflow. In case you want to avoid logs, you should passlogMissingKey: true
and will skip it inallowMissing
andonMissingKey
previous scenarios.Related Issue
fix #1731
Example
How to track translation errors from outside.
How to avoid writing console.warn into browser console
TODO