Skip to content

fix(i18n): extract translations on plugins folder #1589

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

Conversation

igobranco
Copy link
Contributor

fixes #1588

Description

This pull request fixes the extract translations process for the plugins folder.
This increases the messages that are going to be extracted, making it possible to translate more of this application.

This PR is useful for "Operators" that use Studio and Course authoring MFE on a different language than English.

Testing instructions

Run the extract_translations on master and on this PR:

make extract_translations
wc -l temp/babel-plugin-formatjs/Default.messages.json

@igobranco igobranco requested a review from a team as a code owner January 14, 2025 13:02
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jan 14, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Jan 14, 2025

Thanks for the pull request, @igobranco!

This repository is currently maintained by @openedx/2u-tnl.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Jan 15, 2025
@e0d e0d changed the title fix(i18n): extract translations on plugins folder fix(i18n): extract translations on plugins folder Jan 23, 2025
@e0d
Copy link

e0d commented Jan 23, 2025

@igobranco I added you to the triage team so tests will run automatically for you going forward. This PR seems to have stuck jobs, can you push an empty commit or similar to see if it kicks off the checks again?

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.50%. Comparing base (8385c4e) to head (35d164c).
Report is 79 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1589      +/-   ##
==========================================
+ Coverage   93.07%   93.50%   +0.43%     
==========================================
  Files        1092     1128      +36     
  Lines       21617    22925    +1308     
  Branches     4577     4858     +281     
==========================================
+ Hits        20120    21436    +1316     
+ Misses       1431     1421      -10     
- Partials       66       68       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@igobranco
Copy link
Contributor Author

@igobranco I added you to the triage team so tests will run automatically for you going forward. This PR seems to have stuck jobs, can you push an empty commit or similar to see if it kicks off the checks again?

Thanks @e0d

@mphilbrick211 mphilbrick211 removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Jan 29, 2025
@mphilbrick211
Copy link

@openedx/2u-tnl this is ready for review. Thanks!

package.json Outdated
@@ -11,7 +11,7 @@
],
"scripts": {
"build": "fedx-scripts webpack",
"i18n_extract": "fedx-scripts formatjs extract",
"i18n_extract": "formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js*",
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @igobranco for the pull request and really sorry for the delay. Somehow I didn't include this pull request on my todo list.

I'll test locally, but one question. I noticed that you're setting the file to become ./temp/babel-plugin-formatjs/Default.messages.json, what's reason for this specific file choice and why did you mention it explicitly?

Are you aware of the specifics of fedx-scripts formatjs extract? What features do we expect to lose when removing the fedx-scripts meta-script?

@OmarIthawi OmarIthawi self-requested a review April 6, 2025 06:51
Copy link
Member

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

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

Thanks @igobranco for your contribution, please check the comments and let me know what do you think.

package.json Outdated
@@ -11,7 +11,7 @@
],
"scripts": {
"build": "fedx-scripts webpack",
"i18n_extract": "fedx-scripts formatjs extract",
"i18n_extract": "formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js*",
Copy link
Member

Choose a reason for hiding this comment

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

I've checked the fedx-scripts and I think there's a better solution because the fedx-scripts accepts additional arguments and I'd like to ask you to try it first:

Suggested change
"i18n_extract": "formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js*",
"i18n_extract": ""i18n_extract": "fedx-scripts formatjs extract plugins/**/*.js*",

We might need to add quotes, I'm unsure whether bash is running here or not:

Suggested change
"i18n_extract": "formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js*",
"i18n_extract": ""i18n_extract": "fedx-scripts formatjs extract 'plugins/**/*.js*'",

Please check:

https://github.com/openedx/frontend-build/blob/c70ef4e0a5e8702f7144f36b1b23195b94f5e09a/bin/fedx-scripts.js#L71-L81

Copy link
Contributor Author

@igobranco igobranco Apr 9, 2025

Choose a reason for hiding this comment

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

@OmarIthawi
Yes, I checked when I open this PR.

That is why I included ./temp/babel-plugin-formatjs/Default.messages.json because behind the scenes the fedx-scripts is using that.
In general the problem is that the fedx-scripts formatjs don't allow to add additional source folders. But probably this isn't the idea of fedx-scripts of having too much custom options, just a basic framework for different Open edX frontend packages.

So I think this resume the execution, where each step executes the next one:

  1. npm run i18n_extract
  2. fedx-scripts formatjs extract that is installed on node_modules/@openedx/frontend-build/bin/fedx-scripts.js that adds those commonArgs to the next process
  3. node_modules/@formatjs/cli/bin/formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore src/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- src/**/*.js* but this command don't include the plugins folder where this repository has additional code.

So my proposal is to replace the fedx-scripts formatjs extract executing a lower level command directly that also includes the plugins folder.

If you execute this PR before and after you will an increase on the strings to be translated, 145 strings on the branch that I opened the PR.

$ npm run i18n_extract

> @edx/[email protected] i18n_extract
> formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js*

[@formatjs/cli] [WARN] [FormatJS CLI] Duplicate message id: "authoring.proctoring.alert.error", but the `description` and/or `defaultMessage` are different.
$ grep '"id"' temp/babel-plugin-formatjs/Default.messages.json | wc -l
1860

I can't make it run with your proposal:

package.json changed to:

"i18n_extract": "fedx-scripts formatjs extract plugins/**/*.js*",

Execute and output:

$ npm run i18n_extract

> @edx/[email protected] i18n_extract
> fedx-scripts formatjs extract plugins/**/*.js*

Running with resolved config:
/home/ibranco/projects/openedx/frontend-app-authoring/node_modules/@openedx/frontend-build/config/babel.config.js

[@formatjs/cli] [WARN] Error: Error processing file plugins/course-apps/calculator/package.json 
Debug Failure. Output generation failed

Yes, it passes the arguments, but because the fedx-scripts will add more arguments, then the real formatjs executed will be kind of different!

@igobranco igobranco force-pushed the igobranco/issues/1588/translations-extract-plugins-folder branch from a434a17 to 35d164c Compare April 9, 2025 11:35
@igobranco
Copy link
Contributor Author

igobranco commented Apr 9, 2025

@OmarIthawi I reviewed the command.

Changed to:

"i18n_extract": "formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js* {src,plugins}/**/messages.ts",

To include the messages.ts files.

I tested and it has increased the extraction to 2376 strings.

$ npm run i18n_extract &&  grep '"id"' temp/babel-plugin-formatjs/Default.messages.json | wc -l

> @edx/[email protected] i18n_extract
> formatjs extract --format node_modules/@openedx/frontend-build/lib/formatter.js --ignore {src,plugins}/**/*.json --out-file ./temp/babel-plugin-formatjs/Default.messages.json -- {src,plugins}/**/*.js* {src,plugins}/**/messages.ts

[@formatjs/cli] [WARN] [FormatJS CLI] Duplicate message id: "authoring.proctoring.alert.error", but the `description` and/or `defaultMessage` are different.[@formatjs/cli] [WARN] [FormatJS CLI] Duplicate message id: "course-authoring.library-authoring.component.advanced.olx-save", but the `description` and/or `defaultMessage` are different.[@formatjs/cli] [WARN] [FormatJS CLI] Duplicate message id: "course-authoring.library-authoring.create-library", but the `description` and/or `defaultMessage` are different.[@formatjs/cli] [WARN] [FormatJS CLI] Duplicate message id: "course-authoring.library-authoring.publish.error", but the `description` and/or `defaultMessage` are different.



2376

I tested and now I could translate the "Select problem type", the others should also work...
image

Nevertheless, the problem types aren't going to be translated, someone has been creative:

@OmarIthawi
Copy link
Member

Thanks @igobranco for the debugging in and the additional information.

So my proposal is to replace the fedx-scripts formatjs extract executing a lower level command directly that also includes the plugins folder.

I think that makes sense, a more appropriate and acceptable change is to add an argument to the extract command: fedx-scripts formatjs extract --include=plugins --include=plugins2

Which would be more sensible and avoid hidden assumptions.

The issue with removing fedx-scripts use is that future upgrades will break and will cause a hard time for engineers to debug before discovering that frontend-app-authoring is a special case which I don't recommend.

@igobranco
Copy link
Contributor Author

@OmarIthawi to resolve part of the "problem", related to my last comment, I just opened a new PR #1801 that renames the message.ts files to message.js.
And I agree with you a better solution is to improve the https://github.com/openedx/frontend-build/blob/c70ef4e0a5e8702f7144f36b1b23195b94f5e09a/bin/fedx-scripts.js#L71-L81 to support additional source folders.

@igobranco
Copy link
Contributor Author

@OmarIthawi I opened a new PR openedx/frontend-build#650 for frontend-build with your suggestion to add that --include= additional argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Translation: plugins folder not included in extract_translations
5 participants