wordpress-mobile / release-toolkit

Shared tools used in release automation
GNU General Public License v2.0
31 stars 9 forks source link

Fix `android_download_translations` issues #571

Closed AliSoftware closed 3 months ago

AliSoftware commented 3 months ago

Fixes #569 — i.e. the issues that DayOne Android encountered in their last 2024.14 release (See p1720472497193469-slack-CC7L49W13)

What does it do?

Checklist before requesting a review

How to Test

cc @danilo04 @AmandaRiu

What's Next

iangmaia commented 3 months ago

I ran a few tests and while it worked fine, I noticed a few things specially when running on WPAndroid.

I've pushed my iangmaia/translations-fix-tests branch to show some concrete examples:

I don't think these are critical, specially the sorting issue that seems to be there for some time, but it's perhaps good to tackle them in a near future.

AliSoftware commented 3 months ago

Thanks for the thorough testing @iangmaia !

I think this may be a known issue as I remember seeing it before, but […] looking closely, it seems just that the order of some strings changed?

The non-stable order of the nodes is a known issue (I actually don't remember if this comes from GlotPress not guaranteeing the order during export, or from our post-processing, but I think that's the former?), and one we've long wanted to solve.

I wonder if that's from GlotPress or on the Gem side, and if we could force sorting the xml

Yep, that would be the idea, by adding some sorting of the strings post-export during our post-processing of the XML files. We just never found the time to get to that (also I think because sorting an XML might not be as trivial as it looks, e.g. making sure we keep the child nodes of the same <plurals> and <string-array> together, avoiding blank lines that could be inserted by Nokogiri if we remove a node in one place to insert it in another, …). So this will be for another time 😅

But the warnings for the same string, same language showed multiple times:

This is kind of expected, because that string is a string-array and it was warning you about each element of the array that had that issue.

So if you have:

 <string-array name="weekday_selection">
        <item>None</item>
        <item>\@string/monday</item>
        <item>\@string/tuesday</item>
        <item>\@string/wednesday</item>
        <item>\@string/thursday</item>
        <item>\@string/friday</item>
        <item>\@string/saturday</item>
        <item>\@string/sunday</item>
        <item>All</item>
</string-array>

Then it will warn 7 times: one for each of the <item> that contains such a \@string/, but not for the 2 <item> that contain a plain text like None or All.

I considered making the error message include the index of the child item within the string-array, but that would have made the code quite complicated for little benefit. And that would have made it less DRY-able to also cover the similar case of <plurals>, for which the interesting info in the error message wouldn't be the index of the <item> node, but the value of the corresponding @quantity attribute of the offending <item>:

<string name="empty_selection">No item selected</string>
<string name="delete_one">Delete this item?</string>
<plurals name="delete">
  <item quantity="zero">\@string/empty_selection</item>
  <item quantity="one" tools:ignore="ImpliedQuantity">\@string/delete_one</item>
  <item quantity="other">Delete %d items?</item>
</plurals>

I also considered de-duplicating the error messages to only print one, but given the examples above I figured it still made sense to warn as many times as there were violations (one per violating <item> especially since not all <item> children might violate the rule (e.g. <item>None</item>, <item>All</item> and <item quantity="other"> in examples above).

So in the end I figured it was not worth the effort and figure it'd be ok to have as many warnings as there are invalid \@string/ found even if those are on different <item> of the same <string-array> or <plurals>.

AliSoftware commented 3 months ago
  • it (correctly) added quite a few a8c-src-lib= attributes -- which I don't think should be an issue, but I wonder what's the use of them?

For the record, this is an attribute our tooling adds to strings that got merged from libraries, so we can easily identify them and understand where they come from. For more context, see paqN3M-xk-p2 🙂