Skip to content

fix: Changing language doesn't affect echarts charts#31751

Merged
villebro merged 18 commits intoapache:masterfrom
jpchev:fix/issue_30131
Mar 19, 2025
Merged

fix: Changing language doesn't affect echarts charts#31751
villebro merged 18 commits intoapache:masterfrom
jpchev:fix/issue_30131

Conversation

@jpchev
Copy link
Contributor

@jpchev jpchev commented Jan 8, 2025

SUMMARY

this is to propagate the current locale up to the echarts configuration.

fixes: #30131

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

switch the locale and verify that charts have the correct locale (for example in months name and in buttons)

@dosubot dosubot bot added the viz:charts:echarts Related to Echarts label Jan 8, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Functionality Unsafe Dynamic Module Import ▹ view
Functionality Missing Locale Fallback ▹ view
Error Handling Missing locale state fallback ▹ view

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Feedback and Support

}));

const localeObj = useSelector((state: ExplorePageState) => state?.common?.locale);
const lang = require('echarts/lib/i18n/lang' + localeObj.toUpperCase()).default;

This comment was marked as resolved.

@jpchev jpchev changed the title fixes for https://github.com/apache/superset/issues/30131 fix(issue): 30131 Jan 8, 2025
Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this PR @jpchev , you beat me to it :)
With just a few small changes, this is working well for me.

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This change is working great! Thank you @jpchev :)

  • I tested this by combining it with #31692 to test changing languages while viewing and editing the Pie Chart echart. I verified that this change ensures the "Inv" and "All" buttons on that echart are now translated as expected.
  • I read through the code
translate.echarts.mp4

@rusackas
Copy link
Member

rusackas commented Jan 22, 2025

@villebro might be most qualified to look at this one, if he has time. That said, there are some failing tests that could use attention, and a more descritive PR title could help too :D

@jpchev jpchev changed the title fix(issue): 30131 fix(Changing languages doesn't affect echarts charts): 30131 Jan 22, 2025
@jpchev jpchev changed the title fix(Changing languages doesn't affect echarts charts): 30131 fix(Changing languages doesn't affect echarts charts): issue 30131 Jan 22, 2025
@jpchev
Copy link
Contributor Author

jpchev commented Jan 22, 2025

@villebro might be most qualified to look at this one, if he has time. That said, there are some failing tests that could use attention, and a more descritive PR title could help too :D

sorry for the cryptic title, I've put the title of the issue it fixes.
Also, I see one of the checks fails because I used the 'require' import

https://github.com/apache/superset/actions/runs/12825802735/job/35764682648?pr=31751#step:4:4582

I know it's not recommended, but I don't know how to dynamically import a js file without using 'require'.
There is an async alternative, but that would make the code much less clear, in my opinion.

Comment on lines 130 to 149
const locale = useSelector(
(state: ExplorePageState) => state?.common?.locale ?? 'en',
).toUpperCase();
try {
const lang = require(`echarts/lib/i18n/lang${locale}`).default;
registerLocale(locale, lang);
} catch (e) {
console.warn(`Locale ${locale} not supported in ECharts`);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpchev I think we need to use dynamic imports instead, but they're tricky to use in React. I tried a few ways and wasn't able to get it to render properly, so am asking the bot:

@dosu how do we refactor this to ensure we await the import and registerLocale calls before calling init below?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply is here: #30131 (comment)

But it doesn't work :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried something similar, without success. That's why I went for require.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpchev I found the culprit! handleSizeChange wasn't running because of race conditions on render.

See jpchev#2

@jpchev
Copy link
Contributor Author

jpchev commented Jan 24, 2025

@pomegranited I fixed almost all the checks, there is this one left which I don't how to treat https://github.com/apache/superset/actions/runs/12949242972/job/36119814005?pr=31751

do you have an idea? It seems there are errors also on files not impacted by changes in this PR,
for instance

@superset-ui/plugin-chart-echarts: ../../scripts/tsc.sh: line 25: exit: ../../src/components/Icons/Icon.tsx(23,29): error TS2307: Cannot find module 'src/assets/images/icons/transparent.svg' or its corresponding type declarations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert these changes? I don't think they're needed.

@jpchev
Copy link
Contributor Author

jpchev commented Jan 29, 2025

@pomegranited I've pushed again my code from scratch, in order to resolve the conflict on superset-frontend/package-lock.json I think it needs again to be approved

@jpchev
Copy link
Contributor Author

jpchev commented Mar 10, 2025

@jpchev looks like pre-commits are failing, but I think we fixed this in master already. Can you rebase against master?

@sadpandajoe thank you, I've rebased and now all checks pass.
Can somebody please review and merge this PR? @michael-s-molina @kgabryje @justinpark

@jpchev jpchev changed the title fix: Changing languages doesn't affect echarts charts fix: Changing language doesn't affect echarts charts Mar 11, 2025
@jpchev
Copy link
Contributor Author

jpchev commented Mar 18, 2025

@villebro do you know if there is anything I'm missing on this PR to have it reviewed?

@jpchev
Copy link
Contributor Author

jpchev commented Mar 18, 2025

@geido can you please have a look at this PR?

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for the dev dependency being in regular dependencies

"lodash": "^4.17.21",
"dayjs": "^1.11.13"
"dayjs": "^1.11.13",
"@types/react-redux": "^7.1.10"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in devDependencies

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@villebro
Copy link
Member

@jpchev my apologies, for some reason it appears to require having the type package under regular dependencies 🤔 My apologies (not sure why this is, I need to investigate this in more detail..) Anyway, please revert that change and I'll merge when CI is green again.

@jpchev
Copy link
Contributor Author

jpchev commented Mar 19, 2025

@villebro ok, thank you, I reverted the change in order to have the type under dependencies.
The CI is green

@villebro villebro merged commit 78efb62 into apache:master Mar 19, 2025
47 checks passed
@michael-s-molina michael-s-molina added the v5.0 Label added by the release manager to track PRs to be included in the 5.0 branch label Mar 20, 2025
michael-s-molina pushed a commit that referenced this pull request Mar 20, 2025
Co-authored-by: Giampaolo Capelli <giampaolo.capelli@docaposte.fr>
(cherry picked from commit 78efb62)
@jpchev jpchev deleted the fix/issue_30131 branch March 25, 2025 09:13
@mistercrunch mistercrunch added 🍒 5.0.0 Cherry-picked to 5.0.0 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels dependencies:npm plugins size/M v5.0 Label added by the release manager to track PRs to be included in the 5.0 branch viz:charts:echarts Related to Echarts 🍒 5.0.0 Cherry-picked to 5.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing languages doesn't affect echarts charts.

8 participants