-
Notifications
You must be signed in to change notification settings - Fork 9
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
[L10n Tooling: i3] Re-implement download-from-glotpress logic from .py and .swift scripts #331
[L10n Tooling: i3] Re-implement download-from-glotpress logic from .py and .swift scripts #331
Conversation
Took the liberty of adding this to the Localization Toolchain Modernization & Fixes project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far 👍 Also easier to follow than the original scripts. Looking forward to have everything centralized here.
lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_download_strings_files_from_glotpress.rb
Outdated
Show resolved
Hide resolved
Makes more sense to have that default value hosted on the fastlane action rather than the helper.
+ pending test cases
As we don't want the word `GlotPress` to be split and turned into `glot_press` in the action name when called from the Fastfile.
4590c07
to
832343b
Compare
…dy reported) a download failure (e.g. 404)
Depending on the version of plutil installed on the machine, apparently
@mokagio This should now be ready for review 🎉 |
end | ||
|
||
# Assert | ||
expect { act.call }.to raise_error(FastlaneCore::Interface::FastlaneError, "The parent directory `#{download_dir}` (which contains all the `*.lproj` subdirectories) must already exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the exception raised by UI.user_error!
.
PS: Note that we can't really use allow(FastlaneCore::UI).to receive(:user_error!) { |m| … }
here because if we catch and stub those, that won't interrupt the action (i.e. the call here on L9 would not raise if stubbed so the rest of the run
method would continue executing).
(And we could do allow(FastlaneCore::UI).to receive(:user_error!) do |e| raise e }
to be sure that it still interrupts the code even when stubbed… but then what would be the point of stubbing the method while the real implementation already raises…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, wdyt of using a lambda
like this here (which is basically the Ruby equivalent of an anonymous closure in Swift) so that it allowed me to still keep the # Act
and # Assert
separate?
Is it readable and worth it? Or too obscure and you'd instead prefer to avoid the lambda
and directly use expect { run_described_fastlane_action(…) }.to …
… even if that means mixing the "Act" and "Assert" steps together and breaking the usual A/A/A structure of the tests just to be able to catch the exception raised by the "act" part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, wdyt of using a
lambda
like this here...
I think it's a neat trick that doesn't affect the code readability much. Having said that, as much as I like AAA I think it would be okay to break the pattern here to keep the code concise.
Up to your preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'll keep it then 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciated the prod to test code ratio. Even accounting for the boilerplate required by file system access and Fastlane action and UI
, it's still very thorough. Thank you. It makes me trust the code a lot more and will make modifying it in the future easier.
GTG, only left minor non-necessary suggestions.
end | ||
|
||
# Assert | ||
expect { act.call }.to raise_error(FastlaneCore::Interface::FastlaneError, "The parent directory `#{download_dir}` (which contains all the `*.lproj` subdirectories) must already exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, wdyt of using a
lambda
like this here...
I think it's a neat trick that doesn't affect the code readability much. Having said that, as much as I like AAA I think it would be okay to break the pattern here to keep the code concise.
Up to your preference.
Part of the L10n Modernization project paaHJt-2Ib-p2, especially item [i3].
What
This introduces a new
ios_download_strings_files_from_glotpress
action, which is mostly the re-implementation of:Scripts/update-translations.rb
ruby script currently hosted in WPiOS/WCiOS reposScripts/fix-translation
swift script currently hosted in WPiOS/WCiOS reposPS: Obviously, once this lands and the client repos have migrated to use the future new version of the toolkit including that action and start using it, we will completely delete the scripts it replaces from the client repos'
Scripts/
folders.Handling invalid files and empty translations
I've decided to only warn (using a
UI.error
) about the potential case of having empty translations in downloaded exports — as opposed to trying to fix it ourselves like the previousScripts/fix-translation
script was trying to do. There are multiple reasons for this choice:"key" = "";
) in exports in the past seems to have been resolved a long time ago and not be present anymore, at least to my experience and smoke checks in our Mag16 locales.strings
files (downloaded from GlotPress then fixed) were in UTF16 (given the bytes used on thegrep
), while in practice all the downloaded files are all in UTF-8 nowadays (find WordPress/Resources -name 'Localizable.strings' -exec file {} \;
in WPiOS only lists the one fromen.lproj
, aka the original, to be UTF16, and all others downloaded from GlotPress to be UTF8). Which shows how the check was outdated and not even checking correctly what we expected it to fix (as thegrep
would not find those UTF16 bytes in the UTF-8 files anyway)Scripts/fix-translations
consisted in replacing the empty"key" = "";
with"key" = "key";
; but given we want to be open to the possibility of (and start actually adopting) using keys that are different to the English copy (see Project Thread explanations), this would not have been the correct fix anymore, as that would not have been the correct fallback anymore for those cases./= "";$/
with empty lines, or comment those lines out, so that the fallback would instead be to use thevalue:
parameter fromNSLocalizedString(_ key:, value:, comment:)
in the codebase (which would be the English copy, as opposed to the key). But manipulating the textual.strings
file in that way starts raising risks and issues when trying to deal with text encodings (and GlotPress serves those files asapplication/octet-stream
, without explicitly exposing the actual encoding used, even if by experience it looks like UTF8 but we shouldn't make such an assumption if we want our code to be resilient)Given that the bug seems to have been fixed since a long time I figured better avoid trying to fix something that does not exist — and risk messing things up rather than improving them — and instead just detect in case it reappears one day. If we end up seeing it reappear, it will always be time to try to implement a workaround in the action's code, but… YAGNI.
What's next
While this implements most of what's needed to cover item [i3] of the plan (paaHJt-2Ib-p2), we will still need to add another action on top of this one (in a separate, future PR) to re-implement the logic from
Scripts/extract-framework-translations.swift
in a separate fastlane action in order to finally complete [i3] (and [i6]). Most of the logic to do that last step is already present in theios_l10n_helper
so that future PR should be straightforward though.