-
Notifications
You must be signed in to change notification settings - Fork 45
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
Fix Google Translate issues with React #1382
Conversation
// Ban `condition && text node` | ||
{ | ||
selector: | ||
'JSXElement > JSXExpressionContainer > LogicalExpression[operator="&&"]' + | ||
'[right.type!="JSXElement"][right.type!="JSXFragment"]', | ||
message: | ||
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.', | ||
}, | ||
// Ban `condition && <>text node</>` | ||
{ | ||
selector: | ||
'JSXElement > JSXExpressionContainer > LogicalExpression[operator="&&"]' + | ||
' > JSXFragment > .children:not(JSXElement, JSXText[value=/^\\s+$/])', | ||
message: | ||
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.', | ||
}, | ||
// Ban text nodes before or after a condition `text {condition && <span/>} text` | ||
{ | ||
selector: | ||
'JSXElement:has(JSXExpressionContainer.children > LogicalExpression[operator="&&"])' + | ||
' > JSXText[value!=/^\\s+$/]', | ||
message: | ||
'Plain text nodes before or after a condition could break React if used with Google Translate. Wrap text into an element.', | ||
}, | ||
// Ban variables before or after `{var} {condition && <span/>} {var}` (just in case they return a string) | ||
{ | ||
selector: | ||
'JSXElement:has(JSXExpressionContainer.children > LogicalExpression[operator="&&"])' + | ||
' > JSXExpressionContainer:matches([expression.type="Identifier"], [expression.type="CallExpression"])', | ||
message: | ||
'Plain text nodes before or after a condition could break React if used with Google Translate. Identifier could possibly return a string, so wrap it into an element.', | ||
}, | ||
|
||
// Ban `condition ? text node : <span/>` | ||
{ | ||
selector: | ||
'JSXElement > JSXExpressionContainer > ConditionalExpression' + | ||
' > :matches(.consequent, .alternate):not(JSXElement, JSXFragment)', | ||
message: | ||
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.', | ||
}, | ||
// Ban `condition ? <>text node</> : <span/>` | ||
{ | ||
selector: | ||
'JSXElement > JSXExpressionContainer > ConditionalExpression' + | ||
' > JSXFragment > .children:not(JSXElement, JSXText[value=/^\\s+$/])', | ||
message: | ||
'Conditional plain text nodes could break React if used with Google Translate. Wrap text into an element.', | ||
}, | ||
// Ban text nodes before or after a condition `text {condition ? <span/> : <span/>} text` | ||
{ | ||
selector: | ||
'JSXElement:has(JSXExpressionContainer.children > ConditionalExpression)' + | ||
' > JSXText[value!=/^\\s+$/]', | ||
message: | ||
'Plain text nodes before or after a condition could break React if used with Google Translate. Wrap text into an element.', | ||
}, | ||
// Ban variables before or after `{var} {condition ? <span/> : <span/>} {var}` (just in case they return a string) | ||
{ | ||
selector: | ||
'JSXElement:has(JSXExpressionContainer.children > ConditionalExpression)' + | ||
' > JSXExpressionContainer:matches([expression.type="Identifier"], [expression.type="CallExpression"])', | ||
message: | ||
'Plain text nodes before or after a condition could break React if used with Google Translate. Identifier could possibly return a string, so wrap it into an element.', | ||
}, |
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.
This probably covers most potential issues, but there is a possibility of undetectable:
const a = condition ? 'aa' : <span>bb</span>
return <Box>{a}</Box>
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.
We should later make a package out of it, and reuse it on explorer
🦙 MegaLinter status: ✅ SUCCESS
See detailed report in MegaLinter reports |
snapshots |
Deploying with Cloudflare Pages
|
65c087f
to
2121514
Compare
Codecov Report
@@ Coverage Diff @@
## master #1382 +/- ##
==========================================
- Coverage 84.32% 83.41% -0.91%
==========================================
Files 143 144 +1
Lines 3687 3732 +45
Branches 674 710 +36
==========================================
+ Hits 3109 3113 +4
- Misses 578 619 +41
Flags with carried forward coverage won't be shown. Click here to find out more.
|
fixed |
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.
-
src/app/pages/OpenWalletPage/Features/ImportAccountsSelectionModal/index.tsx
L~144 can we wrap {t('openWallet.importAccounts.pageNumber' with span so pagination counter is working when translation is on -
Would add
translate="no"
to AmmountFormatter ticker ~L60
<Language /> | ||
</Box> | ||
<Box pad="small" flex="grow"> | ||
<Text>Language</Text> |
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.
missing i18n label
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.
I think we want to keep this one international. Otherwise if someone gets into French, they can't get out
{!hideTicker && ( | ||
<Text size={size} {...tickerProps}> | ||
{' '} | ||
{ticker} | ||
<NoTranslate>{` ${ticker}`}</NoTranslate> |
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.
Would add translate="no" to AmmountFormatter ticker ~L60
Added, tho I found ticker translation cute
<span> | ||
{t('openWallet.importAccounts.pageNumber', 'Page {{ pageNum }} of {{ totalPages }}', { |
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.
src/app/pages/OpenWalletPage/Features/ImportAccountsSelectionModal/index.tsx
L~144 can we wrap {t('openWallet.importAccounts.pageNumber' with span so pagination counter is working when translation is on
Added. Nice, it works. No idea why it works.
e1b1ae0
to
dbc2d1f
Compare
Fixes #1354