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

feat: add new options merge-po-files and no-segment #134

Merged

Conversation

shadinaif
Copy link
Contributor

@shadinaif shadinaif commented Aug 18, 2023

feat: add two new options, merge-po-files and no-segment

After we passed a lot of steps in FC-0012 project; we see a need to add the following options to extract command because it'll serve us in a shared logic between many other packages (especially XBlocks). So, instead of repeating the same logic in Makefiles; we just add the options. DRY, and more readable

  • --no-segment: we have a logic in extract command that generates (partial files). This is needed because of the complicity of edx-platform. But it creates a burden on small XBlocks that are always interested in the final django.po. Before this option; we have to always rename the generated django-partial.po to django.po. The option will also skip the segment process is any
  • --merge-po-files: small packages (like small XBlocks) don't need to have two separate translation files for HTML and JS. We usually merge the generated file djangojs.po into django.po manually. This option will take care of that without repeating the steps in all small packages
  • Related unit tests added
  • All tests pass successfully
  • Testing behavior in another package (see Local Manual Testing section)

Local Manual Testing

I used xblock-drag-and-drop-v2 locally to test extract command:

  • Set this PR in requirement instead of the current 1.1.0 version. Done in test.in file
- edx-i18n-tools            # For i18n_tool dummy

+ git+https://github.com/Zeit-Labs/i18n-tools.git@b739443cfcfe411c0dfedcc94b245585f1350264#egg=edx-i18n-tools==1.1.0
  • Run make upgrade
  • Remove django.po file and text.po symbolic link from xblock-drag-and-drop-v2/drag_and_drop_v2/conf/locale/en/LC_MESSAGES
  • Update extract_translations command in Makefile
-	cd $(WORKING_DIR) && i18n_tool extract
-	mv $(EXTRACTED_DJANGO_PARTIAL) $(EXTRACTED_DJANGO)
-	# Safely concatenate djangojs if it exists. The file will exist in this repo, but we're trying to follow a pattern
-	# between all repositories that use i18n_tool
-	if test -f $(EXTRACTED_DJANGOJS_PARTIAL); then \
-	  msgcat $(EXTRACTED_DJANGO) $(EXTRACTED_DJANGOJS_PARTIAL) -o $(EXTRACTED_DJANGO) && \
-	  rm $(EXTRACTED_DJANGOJS_PARTIAL); \
-	fi

+	cd $(WORKING_DIR) && i18n_tool extract --merge-po-files --no-segment
+	mv $(EXTRACT_DIR)/django.po $(EXTRACT_DIR)/text.po
  • Run make extract_translations. text.po is generated successfully
  • Commit changes (because there are tests that validate translation to ensure all new are committed)
  • Run py38-django32 and translations-django32 tests of xblock-drag-and-drop-v2 package. All passed

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 18, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Aug 18, 2023

Thanks for the pull request, @shadinaif! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

i18n/extract.py Outdated Show resolved Hide resolved
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch from 30c31f8 to b90f379 Compare August 18, 2023 12:25
@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.02% 🎉

Comparison is base (27025f4) 99.75% compared to head (afabc56) 99.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #134      +/-   ##
==========================================
+ Coverage   99.75%   99.77%   +0.02%     
==========================================
  Files          10       10              
  Lines         401      439      +38     
  Branches       27       31       +4     
==========================================
+ Hits          400      438      +38     
  Partials        1        1              
Files Changed Coverage Δ
tests/test_extract.py 100.00% <100.00%> (ø)

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

@shadinaif shadinaif marked this pull request as ready for review August 18, 2023 13:17
@shadinaif
Copy link
Contributor Author

This one is ready @OmarIthawi @brian-smith-tcril , also tested on another package to ensure it's validity

@OmarIthawi OmarIthawi assigned OmarIthawi and unassigned OmarIthawi Aug 18, 2023
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.

@shadinaif I'm having a bit of a hard time in reviewing this PR.

Would it be too much to ask if we split into two smaller PRs?

I understand that there's a lot of code moved between files, but I would need at least an hour t to review it. Others in the future looking at the code will also need to spent similar time.

Please let me know what do you recommend? (A) Review as-is (B) Split.

tests/test_extract.py Outdated Show resolved Hide resolved
@shadinaif shadinaif marked this pull request as draft August 31, 2023 09:14
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch from b90f379 to d58e142 Compare September 1, 2023 12:33
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 @shadinaif. Would you mind addressing the notes I've written.

The directions is good and I think it makes sense to move forward with it to simplify the XBlock and small repo configurations.

However, I think it's worth paying attention to the developer experience of the tool because very few engineers actually understand the merge/combine logic here and the options we're introducing aren't easy to understand.

Therefore I'm suggesting an interface change.

tests/test_extract.py Outdated Show resolved Hide resolved
tests/test_extract.py Outdated Show resolved Hide resolved
tests/test_extract.py Outdated Show resolved Hide resolved
tests/test_extract.py Outdated Show resolved Hide resolved
i18n/extract.py Outdated Show resolved Hide resolved
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch from d58e142 to f5bcde1 Compare September 4, 2023 08:09
@shadinaif shadinaif marked this pull request as ready for review September 4, 2023 08:37
@OmarIthawi OmarIthawi changed the title feat: add two new options, merge_js and overrite_from_partial feat: add two new options: --merge-js and --no-partial Sep 4, 2023
@OmarIthawi OmarIthawi changed the title feat: add two new options: --merge-js and --no-partial feat: add new options merge-js and no-partial Sep 4, 2023
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch from f5bcde1 to eaf0097 Compare September 4, 2023 15:47
@OmarIthawi
Copy link
Member

OmarIthawi commented Sep 6, 2023

Test 1: Drag and drop xblock ✅

CLI test log
$ cd xblock-drag-and-drop-v2
$ mkvirtualenv ...
$ pip install -e git+https://github.com/Zeit-Labs/i18n-tools.git@shadinaif/new-options-for-extract#egg=edx-i18n-tools==1.1.0
$ make extract_translations 
cd drag_and_drop_v2 && i18n_tool extract --merge-js --no-partial
INFO:i18n.execute:Executing in . ...
INFO:i18n.execute:django-admin makemessages -l en -v0 --ignore="*/css/*" --ignore="public/js/translations/*" --ignore="public/js/vendor/*" -d django
INFO:i18n.execute:Executing in . ...
INFO:i18n.execute:django-admin makemessages -l en -v0 --ignore="*/css/*" --ignore="public/js/translations/*" --ignore="public/js/vendor/*" -d djangojs -e js,jsx
INFO:i18n.extract:Cleaning djangojs-partial.po
INFO:i18n.extract:Cleaning django-partial.po
INFO:i18n.execute:Executing in /home/omar/work/openedx/xblock-drag-and-drop-v2/drag_and_drop_v2/conf/locale/en/LC_MESSAGES ...
INFO:i18n.execute:msgcat django-partial.po djangojs-partial.po -o django-partial.po
INFO:i18n.execute:Deleting file conf/locale/en/LC_MESSAGES/djangojs-partial.po
INFO:i18n.execute:Deleting file conf/locale/en/LC_MESSAGES/django-saved.po
INFO:i18n.execute:Deleting file conf/locale/en/LC_MESSAGES/djangojs-saved.po
WARNING:i18n.execute:File does not exist: conf/locale/en/LC_MESSAGES/djangojs-saved.po
mv drag_and_drop_v2/conf/locale/en/LC_MESSAGES/django.po drag_and_drop_v2/conf/locale/en/LC_MESSAGES/text.po

$ git status
On branch master
Your branch is up to date with 'upstream/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   Makefile
	deleted:    drag_and_drop_v2/conf/locale/en/LC_MESSAGES/django.po
	typechange: drag_and_drop_v2/conf/locale/en/LC_MESSAGES/text.po

It works great, but leaves the following side-effects:

  • The django.po file is deleted.
  • The symlink text.po is now a file.

Admittedly, this behavior isn't going to break anything so it's perhaps clunky but okay to have since XBlocks needs to explicitly use the new flags and those XBlocks should avoid adding the mv rename command.

Test 2: LTI Consumer XBlock ✅

CLI commands and results
$ mkvirtualenv ...
$ pip install -r requirements/test.txt
$ pip install -e git+https://github.com/Zeit-Labs/i18n-tools.git@shadinaif/new-options-for-extract#egg=edx-i18n-tools==1.1.0

$ make extract_translations 
cd lti_consumer && i18n_tool extract --merge-js --no-partial
INFO:i18n.execute:Executing in . ...
INFO:i18n.execute:django-admin makemessages -l en -v0 --ignore="*/css/*" --ignore="*/sass/*" --ignore="public/js/translations/*" --ignore="translations/*" --ignore="locale/*" -d django
INFO:i18n.execute:Executing in . ...
INFO:i18n.execute:django-admin makemessages -l en -v0 --ignore="*/css/*" --ignore="*/sass/*" --ignore="public/js/translations/*" --ignore="translations/*" --ignore="locale/*" -d djangojs -e js,jsx
INFO:i18n.extract:Cleaning django-partial.po
INFO:i18n.extract:Cleaning djangojs-partial.po
INFO:i18n.execute:Executing in /home/omar/work/openedx/xblock-lti-consumer/lti_consumer/locale/en/LC_MESSAGES ...
INFO:i18n.execute:msgcat django-partial.po djangojs-partial.po -o django-partial.po
INFO:i18n.execute:Deleting file locale/en/LC_MESSAGES/djangojs-partial.po
INFO:i18n.execute:Deleting file locale/en/LC_MESSAGES/django-saved.po
WARNING:i18n.execute:File does not exist: locale/en/LC_MESSAGES/django-saved.po
INFO:i18n.execute:Deleting file locale/en/LC_MESSAGES/djangojs-saved.po
WARNING:i18n.execute:File does not exist: locale/en/LC_MESSAGES/djangojs-saved.po
mv lti_consumer/conf/locale/en/LC_MESSAGES/django.po lti_consumer/conf/locale/en/LC_MESSAGES/text.po



$ git status
On branch master
Your branch is up to date with 'upstream/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   Makefile
	deleted:    lti_consumer/conf/locale/en/LC_MESSAGES/django.po
	typechange: lti_consumer/conf/locale/en/LC_MESSAGES/text.po


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.

Works great. Thanks @shadinaif.

I'll ask @sarina or @brian-smith-tcril for a quick review to spot check wordings and design just in case we missed something.

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.

I'm super happy to see this functionality added! I left a comment starting a conversation about a name, and one comment with some wording suggestions, but overall this looks great!

@@ -6,7 +6,7 @@

from . import config

__version__ = '1.1.1'
__version__ = '1.2.0'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just curious; is this being manually updated or do we have automatic semantic versioning of some sort for this repo?

Copy link
Member

@OmarIthawi OmarIthawi Sep 6, 2023

Choose a reason for hiding this comment

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

It's suprisingly hard to answer this 😅. Here's what I've checked:

I've filed an issue for that:

i18n/extract.py Outdated Show resolved Hide resolved
i18n/extract.py Outdated Show resolved Hide resolved
@shadinaif shadinaif changed the title feat: add new options merge-js and no-partial feat: add new options merge-po-files and no-partial Sep 11, 2023
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch 3 times, most recently from 77275d0 to fd75992 Compare September 11, 2023 07:10
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch from fd75992 to 88e81a9 Compare September 11, 2023 07:35
@shadinaif
Copy link
Contributor Author

Thank you @OmarIthawi , thank you @brian-smith-tcril . It is ready now

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 again @shadinaif for making the pull request.

I tested this pull request on the edx platform and here's what I've tried:

make dev.up.lms
make dev.shell.lms
pip install -e git+https://github.com/Zeit-Labs/i18n-tools.git@shadinaif/new-options-for-extract#egg=edx-i18n-tools==1.1.0

I've tried the following commands:

Step 1: Save a copy for master's po files

cp -r en en-master  # save a copy

Step 2: Generate with --no-partial with the original config.yaml file

rm -rf conf/locale/en/; mkdir -p conf/locale/en/LC_MESSAGES; i18n_tool extract --no-partial; find conf/locale/en/
cp -r en en-no-partial

Step 3: Remove the segment section from the config.yaml file and run with --no-partial

rm -rf conf/locale/en/; mkdir -p conf/locale/en/LC_MESSAGES; i18n_tool extract --no-partial; find conf/locale/en/
cp -r en en-no-partial-no-segment

Step 4: Remove the segment section from the config.yaml and run without --no-partial

rm -rf conf/locale/en/; mkdir -p conf/locale/en/LC_MESSAGES; i18n_tool extract; find conf/locale/en/
cp -r en en-no-segment-with-partial

Looking at the files, I've found that the --no-partial still respects the segment section which isn't intended. So I'd like to suggest the following change:

  • Rename --no-partial --> --no-segment
  • Keep the current functionality in which we don't generate partial files.
  • Additionally, the --no-segment options should discard the segment section from the config.yaml.

I recommend checking the attached zip file or trying the results yourself:

@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch 5 times, most recently from 3a85750 to b739443 Compare September 11, 2023 13:45
@shadinaif
Copy link
Contributor Author

Please review again @OmarIthawi . I've tested again on both xblock-drag-and-drop and edx-platform. I believe we nailed it now :)

@OmarIthawi OmarIthawi changed the title feat: add new options merge-po-files and no-partial feat: add new options merge-po-files and no-segment Sep 11, 2023
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.

I think this is super now.

I've done extensive testing to on the named-release/olive.master branch and it produced no difference in terms of msgid which is remarkable!

Full testing script and results is available here: https://gist.github.com/OmarIthawi/3de2704804401a58c01aca1ef5ab3fb5

i18n/extract.py Outdated
'--no-segment',
action='store_true',
help=(
'Renames (django-partial.po) and (djangojs-partial.po) to (django.po) and (djangojs.po) respectively. '
Copy link
Member

@OmarIthawi OmarIthawi Sep 11, 2023

Choose a reason for hiding this comment

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

Suggested change
'Renames (django-partial.po) and (djangojs-partial.po) to (django.po) and (djangojs.po) respectively. '
'Ignore the `segment` section in the `config.yaml` configurations file. '
'Renames (django-partial.po) and (djangojs-partial.po) to (django.po) and (djangojs.po) respectively. '

Copy link
Contributor Author

@shadinaif shadinaif Sep 12, 2023

Choose a reason for hiding this comment

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

@OmarIthawi refactored rephrased:

            help=(
                'Ignore the `segment` section in the `config.yaml` configurations file. Also rename '
                '(django-partial.po) and (djangojs-partial.po) to (django.po) and (djangojs.po) respectively, '
                'which means that the original files will be overwritten after the extraction is completed. This is '
                'helpful when running the `extract` command in small repositories with no segment/merge workflow.'
            )

no-segment: no partial files are generated, because they replaced the original django.po and djangojs.po. Also no segmet workflow is processed
merge-po-files: no djangojs*.po is generated, because it has been merged into django*.po

Refs: FC-0012 OEP-58
Bump version to include --merge-js and --no-partial options
@shadinaif shadinaif force-pushed the shadinaif/new-options-for-extract branch from b739443 to afabc56 Compare September 12, 2023 08:57
@OmarIthawi OmarIthawi merged commit 851c02f into openedx:master Sep 12, 2023
7 checks passed
@openedx-webhooks
Copy link

@shadinaif 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@shadinaif shadinaif deleted the shadinaif/new-options-for-extract branch September 12, 2023 15:10
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.

4 participants