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

wp-cli make-json and Loco Translate support for admin dashboard. #36739

Merged
merged 14 commits into from Mar 20, 2023

Conversation

kenarsuleyman
Copy link
Contributor

@kenarsuleyman kenarsuleyman commented Feb 2, 2023

All Submissions:

Changes proposed in this Pull Request:

Closes #35500 .

  • This PR is a very minor change/addition and does not require testing instructions (if checked you can ignore/remove the next section).

How to test the changes in this Pull Request:

  1. Set WordPress locale to a language that doesn't have official translations for WooCommerce (Ex. Azerbaijan).
  2. Create translations for that language in Loco Translate. There are 3 possible locations for PO file, you can choose any, It's irrelevant.
    *languages/plugins/woocommerce-az.po
    *languages/loco/plugins/woocommerce-az.po
    *plugins/woocommerce/i18n/languages/woocommerce-az.po
  3. Translate couple random words and save. This will compile MO file and generate JSON files in the chosen directory with following format "woocommerce-{locale}-{MD5}.json". AKA "chunks".
  4. De-Activate and Activate WooCommerce to trigger the associated action.
  5. In the chosen directory, chunk files should be combined into single woocommerce-{locale}-wc-admin-app.json file.

Short summary of bug

Due to file format difference between the official and generated chunk files, WooCommerce was unable to generate combined JSON file.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution labels Feb 2, 2023
@woocommercebot woocommercebot requested review from a team, Konamiman, ilyasfoo and moon0326 and removed request for a team February 2, 2023 14:38
@Konamiman
Copy link
Contributor

Hi @kenarsuleyman, thanks for your contribution. Could you please make the following adjustments to your pull request:

  1. Fix the formatting issues outlined here: https://github.com/woocommerce/woocommerce/actions/runs/4075563397/jobs/7038439499, you can do so by using phpcbf and phpcs (available in vendor/bin).
  2. Add a changelog file. You can do so by running pnpm --filter=plugins/woocommerce run changelog add.
  3. Add more detail to the testing instructions: how are files generated and compiled with Loco Translate, and whre's the woocommerce-{locale}-wc-admin-app.json file supposed to be generated?

@kenarsuleyman kenarsuleyman marked this pull request as draft February 3, 2023 15:16
@kenarsuleyman
Copy link
Contributor Author

@Konamiman Thanks for the clear instructions. For some reason, both phpcbf and phpcs got stuck at %98 but I manually tried to fix formatting based on the error log you showed, also added a changelog and more detailed instructions.

@kenarsuleyman kenarsuleyman marked this pull request as ready for review February 4, 2023 10:48
if ( ! isset( $chunk_data['comment']['reference'] ) ) {
// Support for wp-cli --make-json and Loco Translate file format.

if ( ! ( isset( $chunk_data['comment']['reference'] ) || isset( $chunk_data['source'] ) ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better extracting each parser into separate functions rather than lumping them into one. For me, the resulting nested if branch conditions add too much complexity to this function.

An alternative might be to have get_translation_chunk_data, perform heuristics on the file to detect the format, and then call the appropriate parser function for that format.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @kenarsuleyman, Would you be able to make a change as Adrian's suggestion? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @chihsuan since this is only a workaround fix and will get reverted sometime in near future, I might refactor the entire function based on Adrian's suggestion. Right now I don't know how long this fix needs to stay in the codebase. If current version is not suitable for standarts to merge it, I can do it this week.

Copy link
Member

Choose a reason for hiding this comment

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

If current version is not suitable for standarts to merge it, I can do it this week.

Hi @kenarsuleyman Yeah, I think that would be perfect, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @adrianduffell, I wrote separate functions to combine translation chunks after your suggestion. I agree that this made the code more readable only problem is I'm not fully happy how those separate functions ended up with. There are "duplicate looking" lines, they are not exact duplicates, just the same logic for different file formats. Unfortunately, I couldn't think of a more optimized approach.

Copy link
Member

@chihsuan chihsuan Feb 24, 2023

Choose a reason for hiding this comment

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

Hi @kenarsuleyman Just saw you push a new commit, we will review it soon. 👍 Thank you!

Sorry for late notice, @adrianduffell is unavailable.

@adrianduffell
Copy link
Contributor

adrianduffell commented Feb 8, 2023

Hi @kenarsuleyman, thanks for this PR and your contribution. I think it's valuable to fix the bug.

I'd like to better understand why the formats are different between the official and Loco Translate generated files. Is it an error / deviation in the way one of them is generating the files?

I think ideally, we should aim to have the tooling converge to provide the data in the same format, rather than adding complexity at WooCommerce's end in supporting multiple formats.

@kenarsuleyman
Copy link
Contributor Author

Hi @kenarsuleyman, thanks for this PR and your contribution. I think it's valuable to fix the bug.

I'd like to better understand why the formats are different between the official and Loco Translate generated files. Is it an error / deviation in the way one of them is generating the files?

I think ideally, we should aim to have the tooling converge to provide the data in the same format, rather than adding complexity at WooCommerce's end in supporting multiple formats.

About the difference, I also agree to focus on why there is a difference between files in the first place. I checked the changelog for both GlotPress(based on official files, It's generated by GlotPress) and Loco, but couldn't see any reference to this format change.

Since wp-cli and Loco has same formats and GlotPress has a different format, the problem is most likely caused by GlotPress. Do you think is it better to write a workaround like this and revert it after the underlying problem gets fixed, or try to find a way to fix the underlying issue( which I don't exactly know )?

@adrianduffell
Copy link
Contributor

Since wp-cli and Loco has same formats and GlotPress has a different format, the problem is most likely caused by GlotPress. Do you think is it better to write a workaround like this and revert it after the underlying problem gets fixed, or try to find a way to fix the underlying issue( which I don't exactly know )?

Hi @kenarsuleyman, thanks for the explanation. I think it would be good to merge this as a temporary workaround, while aiming to fix the underlying issue in the meantime. We'll want to merge it by Monday 20 Feb to land it safely in the next release.

I'll take a further look this week.

@codecov
Copy link

codecov bot commented Feb 21, 2023

Codecov Report

Merging #36739 (f3f4c90) into trunk (c8074a7) will decrease coverage by 0.0%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             trunk   #36739     +/-   ##
==========================================
- Coverage     46.7%    46.7%   -0.0%     
  Complexity   17178    17178             
==========================================
  Files          429      429             
  Lines        64779    64779             
==========================================
- Hits         30242    30240      -2     
- Misses       34537    34539      +2     
Impacted Files Coverage Δ
plugins/woocommerce/includes/class-wc-tax.php 78.6% <0.0%> (-0.5%) ⬇️

Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! @kenarsuleyman LGTM and tested well.

@moon0326 Could you also look at this when you get a chance? 🙏

@Konamiman
Copy link
Contributor

Konamiman commented Mar 17, 2023

LGTM so I approved, but I'll wait for @moon0326 to take a look too as requested by @chihsuan before merging. Please ping me once that happens.

Copy link
Contributor

@adrianduffell adrianduffell left a comment

Choose a reason for hiding this comment

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

LGTM and tested well! 🚀

@adrianduffell
Copy link
Contributor

Hey @Konamiman, I've reviewed this instead of @moon0326. I'll go ahead and merge now to meet the code freeze deadline.

@adrianduffell adrianduffell merged commit 32fd0a4 into woocommerce:trunk Mar 20, 2023
@github-actions github-actions bot added this to the 7.6.0 milestone Mar 20, 2023
@adrianduffell
Copy link
Contributor

Thanks for the PR @kenarsuleyman !

@kenarsuleyman
Copy link
Contributor Author

Thanks for the PR @kenarsuleyman !

It was pleasure for me 🙌

@kenarsuleyman kenarsuleyman deleted the fix/35500 branch April 14, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

woocommerce-{locale}-wc-admin-app.json not being generated because of incorrect file format.
4 participants