Skip to content

feat(formatjs): support additional src folders #650

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

@igobranco igobranco commented Apr 10, 2025

Enhance the fedx-scripts.js script on formatjs with an option to extract translations on additional source folders.

Example:
--include=plugins --include=plugins2

This PR is required to fix the extraction process on the https://github.com/openedx/frontend-app-authoring/ because there are an additional plugins source folder.

Then the next step is to change the i18n_extract on package.json to include the additional folder on https://github.com/openedx/frontend-app-authoring/blob/04faf54ad8ca74a288c872f1140eafc0aa4f9763/package.json#L14

From:

"i18n_extract": "fedx-scripts formatjs extract",

To:

"i18n_extract": "fedx-scripts formatjs extract --include=plugins",

Additionally it was added a new commit to extract translations from .ts files.

Additional information

openedx/frontend-app-authoring#1589

@igobranco igobranco self-assigned this Apr 10, 2025
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 10, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 10, 2025

Thanks for the pull request, @igobranco!

This repository is currently maintained by @openedx/committers-frontend-build.

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.

Enhance the `fedx-scripts.js` script on `formatjs` with an option to extract translations on additional source folders.
`--include=plugins --include=plugins2`
@igobranco igobranco force-pushed the igobranco/formatjs-additional-src-folders branch from 8c4b01f to fa1a01a Compare April 10, 2025 09:05
@igobranco igobranco marked this pull request as ready for review April 10, 2025 09:08
@igobranco
Copy link
Contributor Author

FYI @OmarIthawi

@brian-smith-tcril
Copy link
Contributor

This approach seems like a reasonable way to add additional directories to extract, but I am curious about the motivation behind this. I'm mostly wondering why the plugins directory in frontend-app-authoring isn't in src.

@igobranco
Copy link
Contributor Author

This approach seems like a reasonable way to add additional directories to extract, but I am curious about the motivation behind this. I'm mostly wondering why the plugins directory in frontend-app-authoring isn't in src.

@brian-smith-tcril
I'm not an expert on the frontend-app-authoring...
Do you think that I should include your proposal and my ignore the *.d.ts files on this PR?
openedx/frontend-app-authoring#1801 (comment)

@brian-smith-tcril
Copy link
Contributor

Do you think that I should include your proposal and my ignore the *.d.ts files on this PR? openedx/frontend-app-authoring#1801 (comment)

That sounds good to me! Thanks!

@OmarIthawi
Copy link
Member

Thanks @igobranco and sorry for keeping you jumping between PRs. This is the nature of opensource contribution in opensource projects, but I with a bit of effort we'll get this improvement for everyone and it'll be a happy moment when we get your PR merged.

As a long time contributor, I face this issue almost for all non-trivial changes. So I appreciate you pushing through this contribution.

Thanks for @brian-smith-tcril for the review :)

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.

It looks good to me. However, I haven't tested it and my Node.js skills are a bit rusty.

I recommend having another one like @brian-smith-tcril or whoever is maintaing this repository to review it.

Thanks @igobranco

Allow to extract messages to be translated on .ts files.
@igobranco
Copy link
Contributor Author

@OmarIthawi @brian-smith-tcril

I've added a new commit to this PR, with the @brian-smith-tcril suggestion.
I had to skip the *.d.ts files.

The increase of extracted translations is big on both authoring and learning MFEs, but on learner-dashboard it don't extract any more more strings.

Running the command before and after the change:

npm run i18n_extract && grep '"id"' temp/babel-plugin-formatjs/Default.messages.json | wc -l
project from to
frontend-app-authoring 1730 2309
frontend-app-learning 126 499
frontend-app-learner-dashboard 144 144

I tested on 3 repositories and it works, at least don't crash!

@bradenmacdonald
Copy link
Contributor

bradenmacdonald commented Apr 10, 2025

I am curious about the motivation behind this. I'm mostly wondering why the plugins directory in frontend-app-authoring isn't in src.

That was my decision, and I don't remember if it was necessary for technical reasons or not. But I think the main motivation was this: if the plugins are in the src folder, they may benefit from special features of the MFE environment and build system, and when someone comes along and tries to build a third-party plugin that's not part of the MFE, it may not be able to achieve similar things because it doesn't live in the src directory. So keeping them outside of src was a way of ensuring that their code was relatively independent, at least in theory ("if it works from outside the src directory and has its own package.json, it could just as easily be in a separate NPM package"). The entire course-apps plugins system of the authoring MFE is very idiosyncratic and experimental though, so at some point I'd like to find a better approach.

@brian-smith-tcril
Copy link
Contributor

Thanks for providing that context @bradenmacdonald! With that in mind, are you happy with the syntax this PR adds? I think --include=myAdditionalDirectory seems reasonable, but I'd love to hear your thoughts on the matter!

@bradenmacdonald
Copy link
Contributor

I agree it seems reasonable. But maybe we can add a comment to state what our one and only use case is at the moment so that in the future we can remove this if we no longer need it.

@brian-smith-tcril
Copy link
Contributor

A comment about the use case sounds great!

@igobranco would you mind adding a comment mentioning the plugins directory in frontend-app-authoring specifically?

Document the only reason why it was added the --include option on the formatjs in fedx-script.js.
The intention use case is to allow extraction from the 'plugins' directory on 'frontend-app-authoring'.
@igobranco
Copy link
Contributor Author

Added a new commit with that comment.

Copy link
Contributor

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

Thanks a lot for figuring this out!

@brian-smith-tcril brian-smith-tcril merged commit 4a5559b into openedx:master Apr 11, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in Contributions Apr 11, 2025
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (7f26332) to head (95d874a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@      Coverage Diff      @@
##   master   #650   +/-   ##
=============================
=============================

☔ 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.

@openedx-semantic-release-bot

🎉 This PR is included in version 14.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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 released
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants