Hey everyone!
If you are using the Canva app localization process, this a call to action for you.
What’s New
We’ve made some improvements to our i18n eslint config. This new config will help you localize better by linting against unlocalized App UI Kit props. For example:
// ❌ Not recommended, messages will not be localized.
<Button ariaLabel="Click me">..</Button>
// ~~~~~~~~~~~~~~~~~~~~
// error: Cannot have untranslated text in JSX eslintformatjs/no-literal-string-in-jsx
// ✅ Recommended, messages will be localized.
const intl = useIntl();
<Button .. ariaLabel={intl.formatMessage({..})} >..</Button>
Getting started
To get the new config, just copy these new i18n rules from the recently updated starter kit.
Additional tips
If you encounter any false positives where the lint rule shows errors incorrectly,
suppress the error:
<MyComponent
// eslint-disable-next-line formatjs/no-literal-string-in-jsx
name="notUserFacingText"
/>
Or alternatively:
"formatjs/no-literal-string-in-jsx": [
2,
{
props: {
exclude: [
// ...
+ [”MyComponent”, “name”]
],
If you want to ensure localized props for your other components, add them to your eslint config. For example, to ensure the helperText prop of MyComponent is passed a localized message, we would add the following:
"formatjs/no-literal-string-in-jsx": [
2,
{
props: {
include: [
// ...
["FormField", "error"],
+ [”MyComponent”, “helperText”]
],
If you have any feedback on these rules, please let us know.
Happy localizing!