-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Tooling] Fix issue with en-US release notes not generated if en-GB was not translated #17341
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
# First are the locales which are used for *both* downloading the `strings.xml` files from GlotPress *and* for generating the release notes XML files. | ||
{ glotpress: 'ar', android: 'ar', google_play: 'ar', promo_config: {} }, | ||
{ glotpress: 'de', android: 'de', google_play: 'de-DE', promo_config: {} }, | ||
{ glotpress: 'en-gb', android: 'en-rGB', google_play: 'en-US', promo_config: {} }, | ||
{ glotpress: 'es', android: 'es', google_play: 'es-ES', promo_config: {} }, | ||
{ glotpress: 'fr', android: 'fr-rCA', google_play: 'fr-CA', promo_config: false }, | ||
{ glotpress: 'fr', android: 'fr', google_play: 'fr-FR', promo_config: {} }, | ||
|
@@ -95,78 +94,36 @@ | |
##################################################################################### | ||
desc 'Updates the PlayStoreStrings.po files for WP + JP' | ||
lane :update_appstore_strings do |options| | ||
update_wordpress_appstore_strings(options) | ||
update_jetpack_appstore_strings(options) | ||
end | ||
|
||
##################################################################################### | ||
# update_wordpress_appstore_strings | ||
# ----------------------------------------------------------------------------------- | ||
# This lane gets the data from the txt files in the `WordPress/metadata/` folder | ||
# and updates the `.po` file that is then picked by GlotPress for translations. | ||
# ----------------------------------------------------------------------------------- | ||
# Usage: | ||
# fastlane update_wordpress_appstore_strings [version:<version>] | ||
# | ||
# Example: | ||
# fastlane update_wordpress_appstore_strings version:10.3 | ||
##################################################################################### | ||
desc 'Updates the PlayStoreStrings.po file for WordPress' | ||
lane :update_wordpress_appstore_strings do |options| | ||
metadata_folder = File.join(Dir.pwd, '..', 'WordPress', 'metadata') | ||
version = options.fetch(:version, android_get_app_version) | ||
|
||
# <key in po file> => <path to txt file to read the content from> | ||
files = { | ||
release_note: File.join(metadata_folder, 'release_notes.txt'), | ||
release_note_short: File.join(metadata_folder, 'release_notes_short.txt'), | ||
play_store_app_title: File.join(metadata_folder, 'title.txt'), | ||
play_store_promo: File.join(metadata_folder, 'short_description.txt'), | ||
play_store_desc: File.join(metadata_folder, 'full_description.txt') | ||
} | ||
files.merge!((1..9).map do |n| | ||
[:"play_store_screenshot_#{n}", File.join(metadata_folder, "screenshot_#{n}.txt")] | ||
end.to_h) | ||
|
||
update_po_file_for_metadata_localization( | ||
po_path: File.join(metadata_folder, 'PlayStoreStrings.po'), | ||
sources: files, | ||
release_version: version, | ||
commit_message: "Update WordPress `PlayStoreStrings.po` for version #{version}" | ||
) | ||
end | ||
|
||
##################################################################################### | ||
# update_jetpack_appstore_strings | ||
# ----------------------------------------------------------------------------------- | ||
# This lane gets the data from the txt files in the `WordPress/jetpack_metadata/` folder | ||
# and updates the `.po` file that is then picked by GlotPress for translations. | ||
# ----------------------------------------------------------------------------------- | ||
# Usage: | ||
# fastlane update_jetpack_appstore_strings [version:<version>] | ||
# | ||
# Example: | ||
# fastlane update_jetpack_appstore_strings version:10.3 | ||
##################################################################################### | ||
desc 'Updates the PlayStoreStrings.po file for Jetpack' | ||
lane :update_jetpack_appstore_strings do |options| | ||
metadata_folder = File.join(Dir.pwd, '..', 'WordPress', 'jetpack_metadata') | ||
version = options.fetch(:version, android_get_app_version) | ||
# If no `app:` is specified, call this for both WordPress and Jetpack | ||
apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym) | ||
|
||
apps.each do |app| | ||
app_values = APP_SPECIFIC_VALUES[app] | ||
|
||
metadata_folder = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir]) | ||
version = options.fetch(:version, android_get_app_version) | ||
|
||
# <key in po file> => <path to txt file to read the content from> | ||
files = { | ||
release_note: File.join(metadata_folder, 'release_notes.txt'), | ||
release_note_short: File.join(metadata_folder, 'release_notes_short.txt'), | ||
play_store_app_title: File.join(metadata_folder, 'title.txt'), | ||
play_store_promo: File.join(metadata_folder, 'short_description.txt'), | ||
play_store_desc: File.join(metadata_folder, 'full_description.txt') | ||
} | ||
# Add entries for `screenshot_*.txt` files as well | ||
Dir.glob('screenshot_*.txt', base: metadata_folder).sort.each do |screenshot_file| | ||
key = "play_store_#{File.basename(screenshot_file, '.txt')}".to_sym | ||
files[key] = File.join(metadata_folder, screenshot_file) | ||
end | ||
|
||
files = { | ||
release_note: File.join(metadata_folder, 'release_notes.txt'), | ||
release_note_short: File.join(metadata_folder, 'release_notes_short.txt'), | ||
play_store_app_title: File.join(metadata_folder, 'title.txt'), | ||
play_store_promo: File.join(metadata_folder, 'short_description.txt'), | ||
play_store_desc: File.join(metadata_folder, 'full_description.txt') | ||
} | ||
|
||
update_po_file_for_metadata_localization( | ||
po_path: File.join(metadata_folder, 'PlayStoreStrings.po'), | ||
sources: files, | ||
release_version: version, | ||
commit_message: "Update Jetpack `PlayStoreStrings.po` for version #{version}" | ||
) | ||
update_po_file_for_metadata_localization( | ||
po_path: File.join(metadata_folder, 'PlayStoreStrings.po'), | ||
sources: files, | ||
release_version: version, | ||
commit_message: "Update #{app_values[:display_name]} `PlayStoreStrings.po` for version #{version}" | ||
) | ||
end | ||
end | ||
|
||
# Updates the metadata in the Play Store (Main store listing) from the content of `fastlane/{metadata|jetpack_metadata}/android/*/*.txt` files | ||
|
@@ -209,70 +166,47 @@ | |
##################################################################################### | ||
desc 'Downloads translated metadata from GlotPress' | ||
lane :download_metadata_strings do |options| | ||
download_wordpress_metadata_strings(options) | ||
download_jetpack_metadata_strings(options) | ||
end | ||
|
||
desc "Downloads WordPress's translated metadata from GlotPress" | ||
lane :download_wordpress_metadata_strings do |options| | ||
app_values = APP_SPECIFIC_VALUES[:wordpress] | ||
values = options[:version].split('.') | ||
files = { | ||
"release_note_#{values[0]}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 500, alternate_key: "release_note_short_#{values[0]}#{values[1]}" }, | ||
play_store_app_title: { desc: 'title.txt', max_size: 30 }, | ||
play_store_promo: { desc: 'short_description.txt', max_size: 80 }, | ||
play_store_desc: { desc: 'full_description.txt', max_size: 4000 } | ||
} | ||
|
||
delete_old_changelogs(app: 'wordpress', build: options[:build_number]) | ||
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android') | ||
# The case for the source locale (en-US) is pulled in a hacky way, by having an {en-gb => en-US} mapping as part of the WP_RELEASE_NOTES_LOCALES, | ||
# which is then treated in a special way by gp_downloadmetadata by specifying a `source_locale: 'en-US'` to process it differently from the rest. | ||
gp_downloadmetadata( | ||
project_url: app_values[:glotpress_metadata_project], | ||
target_files: files, | ||
locales: WP_RELEASE_NOTES_LOCALES, | ||
source_locale: 'en-US', | ||
download_path: download_path | ||
) | ||
|
||
git_add(path: download_path) | ||
git_commit(path: download_path, message: "Update WordPress metadata translations for #{options[:version]}", allow_nothing_to_commit: true) | ||
push_to_git_remote | ||
end | ||
|
||
desc "Downloads Jetpack's translated metadata from GlotPress" | ||
lane :download_jetpack_metadata_strings do |options| | ||
UI.message('Hey') | ||
app_values = APP_SPECIFIC_VALUES[:jetpack] | ||
values = options[:version].split('.') | ||
files = { | ||
"release_note_#{values[0]}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 500, alternate_key: "release_note_short_#{values[0]}#{values[1]}" }, | ||
play_store_app_title: { desc: 'title.txt', max_size: 30 }, | ||
play_store_promo: { desc: 'short_description.txt', max_size: 80 }, | ||
play_store_desc: { desc: 'full_description.txt', max_size: 4000 } | ||
} | ||
|
||
delete_old_changelogs(app: 'jetpack', build: options[:build_number]) | ||
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android') | ||
gp_downloadmetadata( | ||
project_url: app_values[:glotpress_metadata_project], | ||
target_files: files, | ||
locales: JP_RELEASE_NOTES_LOCALES, | ||
download_path: download_path | ||
) | ||
|
||
# For WordPress, the en-US release notes come from using the source keys (instead of translations) downloaded from GlotPress' en-gb locale (which is unused otherwise). | ||
# But for Jetpack, we don't have an unused locale like en-gb in the GP release notes project, so copy from source instead as a fallback | ||
metadata_source_dir = File.join(Dir.pwd, '..', 'WordPress', 'jetpack_metadata') | ||
FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{options[:build_number]}.txt")) | ||
FileUtils.cp( | ||
['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) }, | ||
File.join(download_path, 'en-US') | ||
) | ||
version = options.fetch(:version, android_get_app_version) | ||
build_number = options.fetch(:build_number, android_get_release_version['code']) | ||
|
||
# If no `app:` is specified, call this for both WordPress and Jetpack | ||
apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym) | ||
|
||
apps.each do |app| | ||
app_values = APP_SPECIFIC_VALUES[app] | ||
|
||
version_suffix = version.split('.').join | ||
files = { | ||
"release_note_#{version_suffix}" => { desc: "changelogs/#{build_number}.txt", max_size: 500, alternate_key: "release_note_short_#{version_suffix}" }, | ||
play_store_app_title: { desc: 'title.txt', max_size: 30 }, | ||
play_store_promo: { desc: 'short_description.txt', max_size: 80 }, | ||
play_store_desc: { desc: 'full_description.txt', max_size: 4000 } | ||
} | ||
|
||
delete_old_changelogs(app: app, build: build_number) | ||
|
||
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android') | ||
locales = { wordpress: WP_RELEASE_NOTES_LOCALES, jetpack: JP_RELEASE_NOTES_LOCALES }[app] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this info should go into But for this to be possible, I'd need to first finish my long-postponed work on adding a Locale Helper to the So I thought that this solution for this line would do in the meantime; I really hope I can continue and finish my work on the Locale Helper in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤞 ❤️ 🙏 |
||
UI.header("Downloading metadata translations for #{app_values[:display_name]}") | ||
gp_downloadmetadata( | ||
project_url: app_values[:glotpress_metadata_project], | ||
target_files: files, | ||
locales: locales, | ||
download_path: download_path | ||
) | ||
|
||
git_add(path: download_path) | ||
git_commit(path: download_path, message: "Update Jetpack metadata translations for #{options[:version]}", allow_nothing_to_commit: true) | ||
# Copy the source `.txt` files (used as source of truth when we generated the `.po`) to the `fastlane/*metadata/android/en-US` dir, | ||
# as `en-US` is the source language, and isn't exported from GlotPress during `gp_downloadmetadata` | ||
metadata_source_dir = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir]) | ||
FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{build_number}.txt")) | ||
FileUtils.cp( | ||
['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) }, | ||
File.join(download_path, 'en-US') | ||
) | ||
|
||
git_add(path: download_path) | ||
git_commit(path: download_path, message: "Update #{app_values[:display_name]} metadata translations for #{version}", allow_nothing_to_commit: true) | ||
end | ||
push_to_git_remote | ||
end | ||
|
||
|
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.
Suggestion (💡): I find lots of references to this 'WordPress' folder here and there, and it took me some seconds to make sure that this code is not doing something specific for the WordPress vs. the Jetpack case, thus maybe it it time we extract this constant to some naming convention that doesn't reference
WordPress
, but applies toJetpack
as well, something like APP_MODULE_FOLDER = 'WordPress'. Wdyt? 🤔PS.1: I am also seeing lot of lowercased constants like 'wordpress' and
jetpack
, for theapp
andapp_flavor
parameters. If you like my above suggestion I would also make an additional effort now and extract those into constants as well, just so to make those explicit and possibly in the future more mainstream, like:app
app_flavor
Maybe adding the above to the
APP_SPECIFIC_VALUES
values is the right way, or reuse them from there, or somewhere else, I am not sure, but I would love to not have it there as is, like a magic number not being explicitly extracted to a constant... 🤔PS.2: All these suggestions apply to all such fastlane files, not just
localization.rb
, but we can start with that if extracting for all is too out-of-scope for this PR. 🤔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.
Note that this
WordPress/
folder is referencing the folder at the root of the repo. We don't have aJetpack
folder at the root of the repo, just aWordPress/
one (and then we have subfolders insrc
formain
vswordpress
vsjetpack
for the different flavors).I'm totally ok to extract that
WordPress
root folder name into some constant likeAPP_MODULE_FOLDER
, though.I'm also OK in adding an
app_flavor
entry to theAPP_SPECIFIC_VALUES
hash, to separate the name of the key used (which was based on the app flavor name to begin with, because we had to choose something to base theapp:
keys off of 😛 … but we can totally make the name of the app flavor explicit as anapp_flavor
entry to make the key used forAPP_SPECIFIC_VALUES
and the app flavor disconnected)I plan to do that in a separate PR though, in fact I already have a WIP branch that cleans up some of those constants and the
APP_SPECIFIC_VALUES
that I plan to improve further 🙂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.
Yeap, I know, I understand that to 100%, but this is just unfortunate because
Jetpack
was born later and reused theWordPress
codebase! 👍Exactly, thanks, having to refer to a
module
instead ofWordPress
seems a much better choice.👍
Coolio, thanks for even considering! 🥇