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
PoC - Typed Translations #24250
base: develop
Are you sure you want to change the base?
PoC - Typed Translations #24250
Conversation
sadly we can only test against TS files not JS files...
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
// t('holdToRevealContentPrivateKey1'); | ||
// t('holdToRevealContentPrivateKey2'); | ||
// t('holdToRevealContent1'); | ||
// t('holdToRevealContent2'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The yarn verify-locales
still works if we just add these as comments - don't need to actually call the translations.
const messageKey = `nameProvider_${ | ||
sourceId as 'ens' | 'etherscan' | 'lens' | 'token' | ||
}` as const; | ||
return t(messageKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quirk due to the translations being a bit more strict - it doesn't accept any arbitrary string.
Meh we can loosen it or have a separate type definition.
In fact could slowly migrate from a loose function definition to a strict function definition if we wanted to.
mergedAccountsProps.isAccountActive | ||
? Boolean(t('active')) | ||
: Boolean(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, this isActive expects a boolean, but we were passing it a string | null
@@ -101,7 +101,7 @@ const getDisplayValues = ({ | |||
} else if (isSmartTransactionCancelled) { | |||
return { | |||
title: t('smartTransactionCancelled'), | |||
description: t('smartTransactionCancelledDescription', [countdown]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect example! This translation doesn't need an argument!
Thankfully from the files I could test (only typescript files), there weren't any issues where we were using translations but forgetting to pass args.
Description
Just me having some fun.
This actually works really well! It can inform developers if they are using a translation that does not exist, and if they have missed (or forgot to remove) translation arguments.
but 2 blockers.
// @ts-check
Related issues
Fixes: N/A (just improving types & experimenting)
Manual testing steps
N/A
Screenshots/Recordings
Some TS Error Examples 😄
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist