Skip to content
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

kolibri-tools: Accept multiple --namespace/--searchPath arguments #11357

Conversation

pwithnall
Copy link
Contributor

@pwithnall pwithnall commented Oct 5, 2023

Summary

This is needed when a plugin has more than one sub-package which contains translatable strings. All the strings from all the packages need to be pulled into the *-messages.json file which is injected into the frontend output — but currently only at most one sub-package is supported. For Kolibri itself, this is kolibri-common. The kolibri-explore-plugin, however, has at least two sub-packages.

This commit changes the --namespace and --searchPath options to allow them to be specified multiple times. For example, --namespace ek-components --searchPath ./packages/ek-components --namespace template-ui --searchPath ./packages/template-ui. It shouldn’t change the behaviour when they are passed zero or one times, as before, so this change should be backwards-compatible.

The strings from each namespace are still outputted into a per-namespace
CSV file, with the assumption that the translation step (when CSVs are
turned into JSON files) will combine them all into a single JSON file
suitable for webpack to load.

See endlessm/kolibri-explore-plugin#846

References

Reviewer guidance

yarn exec kolibri-tools i18n-extract-messages --plugins kolibri_explore_plugin --namespace ek-components --searchPath ./packages/ek-components --namespace template-ui --searchPath ./packages/template-ui

vs

yarn exec kolibri-tools i18n-extract-messages --plugins kolibri_explore_plugin && kolibri-tools i18n-extract-messages --namespace ek-components --searchPath ./packages/ek-components && kolibri-tools i18n-extract-messages --namespace template-ui --searchPath ./packages/template-ui

(This relies on running in kolibri-explore-plugin, as that’s the motivator for this fix.)


Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@pwithnall
Copy link
Contributor Author

At the 11th hour I’ve just noticed that this might need further changes, to put all the extracted messages into a single CSV file rather than one per namespace. I’ll look at that tomorrow. Sorry for missing that earlier.

The rest of the changes are ready to be reviewed at a high level though.

@pwithnall pwithnall marked this pull request as draft October 5, 2023 17:32
This is needed when a plugin has more than one sub-package which
contains translatable strings. All the strings from all the packages
need to be pulled into the `*-messages.json` file which is injected into
the frontend output — but currently only at most one sub-package is
supported. For Kolibri itself, this is kolibri-common. The
kolibri-explore-plugin, however, has at least two sub-packages.

This commit changes the `--namespace` and `--searchPath` options to
allow them to be specified multiple times. For example, `--namespace
ek-components --searchPath ./packages/ek-components --namespace
template-ui --searchPath ./packages/template-ui`. It shouldn’t change
the behaviour when they are passed zero or one times, as before, so this
change should be backwards-compatible.

The strings from each namespace are still outputted into a per-namespace
CSV file, with the assumption that the translation step (when CSVs are
turned into JSON files) will combine them all into a single JSON file
suitable for webpack to load.

See endlessm/kolibri-explore-plugin#846

Signed-off-by: Philip Withnall <[email protected]>
@pwithnall pwithnall force-pushed the kolibri-tools-more-namespaces branch from 550fd1c to f7442ef Compare October 6, 2023 14:26
@pwithnall
Copy link
Contributor Author

At the 11th hour I’ve just noticed that this might need further changes, to put all the extracted messages into a single CSV file rather than one per namespace. I’ll look at that tomorrow. Sorry for missing that earlier.

The rest of the changes are ready to be reviewed at a high level though.

Done. I had got mixed up in my head about whether all the strings from all namespaces are outputted to a single file (which is incorrect); it’s actually that they’re all outputted to per-namespace CSV files. That’s fine, and it’s not a behaviour change from the current kolibri-tools behaviour.

Ready for review.

@pwithnall pwithnall marked this pull request as ready for review October 6, 2023 14:27
pwithnall added a commit to endlessm/kolibri-explore-plugin that referenced this pull request Oct 6, 2023
This speeds up the i18n extraction process, but it cannot remove the
need for the workaround from
#846 where the
per-namespace CSV files need to be combined into a single JSON file for
webpack to load. Currently that’s done manually.

This commit is still WIP as it needs a kolibri-tools version bump to be
able to rely on the new behaviour, which is currently unmerged upstream
at learningequality/kolibri#11357, and not in a
release yet.

Signed-off-by: Philip Withnall <[email protected]>

Helps: #846
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Code changes look correct, and this doesn't seem to impact existing behaviour, so this seems fine to me!

@rtibbles rtibbles merged commit 358bb82 into learningequality:release-v0.16.x Oct 8, 2023
@rtibbles
Copy link
Member

rtibbles commented Oct 8, 2023

Has been published to npm as next.

@pwithnall pwithnall deleted the kolibri-tools-more-namespaces branch October 19, 2023 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants