Skip to content

Commit 628c372

Browse files
committed
Remove the en-gb => en-US hack for WP metadata
And instead just copy the files from the `WordPress/*metadata/*` source dir to `fastlane/*metadata/android/en-US` dir instead of relying on the odd and buggy `source_locale` parameter of `gp_downloadmetadata` This is to address the recurring issue we've been encountering with English release notes failing to be generated in `fastlane/metadata` when there were no `en-GB` translation for it in GlotPress (and thus the export for it was empty) See also pdnsEh-jJ-p2#comment-1233
1 parent bf8788d commit 628c372

File tree

3 files changed

+43
-65
lines changed

3 files changed

+43
-65
lines changed

fastlane/Fastfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ UI.user_error!('Please run fastlane via `bundle exec`') unless FastlaneCore::Hel
22

33
APP_SPECIFIC_VALUES = {
44
wordpress: {
5+
display_name: 'WordPress',
56
metadata_dir: 'metadata',
67
glotpress_appstrings_project: 'https://translate.wordpress.org/projects/apps/android/dev/',
78
glotpress_metadata_project: 'https://translate.wordpress.org/projects/apps/android/release-notes/',
89
package_name: 'org.wordpress.android',
910
bundle_name_prefix: 'wpandroid'
1011
},
1112
jetpack: {
13+
display_name: 'Jetpack',
1214
metadata_dir: 'jetpack_metadata',
1315
glotpress_appstrings_project: 'https://translate.wordpress.com/projects/jetpack/apps/android/',
1416
glotpress_metadata_project: 'https://translate.wordpress.com/projects/jetpack/apps/android/release-notes/',

fastlane/lanes/localization.rb

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# First are the locales which are used for *both* downloading the `strings.xml` files from GlotPress *and* for generating the release notes XML files.
1212
{ glotpress: 'ar', android: 'ar', google_play: 'ar', promo_config: {} },
1313
{ glotpress: 'de', android: 'de', google_play: 'de-DE', promo_config: {} },
14-
{ glotpress: 'en-gb', android: 'en-rGB', google_play: 'en-US', promo_config: {} },
1514
{ glotpress: 'es', android: 'es', google_play: 'es-ES', promo_config: {} },
1615
{ glotpress: 'fr', android: 'fr-rCA', google_play: 'fr-CA', promo_config: false },
1716
{ glotpress: 'fr', android: 'fr', google_play: 'fr-FR', promo_config: {} },
@@ -209,70 +208,47 @@
209208
#####################################################################################
210209
desc 'Downloads translated metadata from GlotPress'
211210
lane :download_metadata_strings do |options|
212-
download_wordpress_metadata_strings(options)
213-
download_jetpack_metadata_strings(options)
214-
end
215-
216-
desc "Downloads WordPress's translated metadata from GlotPress"
217-
lane :download_wordpress_metadata_strings do |options|
218-
app_values = APP_SPECIFIC_VALUES[:wordpress]
219-
values = options[:version].split('.')
220-
files = {
221-
"release_note_#{values[0]}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 500, alternate_key: "release_note_short_#{values[0]}#{values[1]}" },
222-
play_store_app_title: { desc: 'title.txt', max_size: 30 },
223-
play_store_promo: { desc: 'short_description.txt', max_size: 80 },
224-
play_store_desc: { desc: 'full_description.txt', max_size: 4000 }
225-
}
226-
227-
delete_old_changelogs(app: 'wordpress', build: options[:build_number])
228-
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android')
229-
# 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,
230-
# 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.
231-
gp_downloadmetadata(
232-
project_url: app_values[:glotpress_metadata_project],
233-
target_files: files,
234-
locales: WP_RELEASE_NOTES_LOCALES,
235-
source_locale: 'en-US',
236-
download_path: download_path
237-
)
238-
239-
git_add(path: download_path)
240-
git_commit(path: download_path, message: "Update WordPress metadata translations for #{options[:version]}", allow_nothing_to_commit: true)
241-
push_to_git_remote
242-
end
243-
244-
desc "Downloads Jetpack's translated metadata from GlotPress"
245-
lane :download_jetpack_metadata_strings do |options|
246-
UI.message('Hey')
247-
app_values = APP_SPECIFIC_VALUES[:jetpack]
248-
values = options[:version].split('.')
249-
files = {
250-
"release_note_#{values[0]}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 500, alternate_key: "release_note_short_#{values[0]}#{values[1]}" },
251-
play_store_app_title: { desc: 'title.txt', max_size: 30 },
252-
play_store_promo: { desc: 'short_description.txt', max_size: 80 },
253-
play_store_desc: { desc: 'full_description.txt', max_size: 4000 }
254-
}
255-
256-
delete_old_changelogs(app: 'jetpack', build: options[:build_number])
257-
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android')
258-
gp_downloadmetadata(
259-
project_url: app_values[:glotpress_metadata_project],
260-
target_files: files,
261-
locales: JP_RELEASE_NOTES_LOCALES,
262-
download_path: download_path
263-
)
264-
265-
# 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).
266-
# 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
267-
metadata_source_dir = File.join(Dir.pwd, '..', 'WordPress', 'jetpack_metadata')
268-
FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{options[:build_number]}.txt"))
269-
FileUtils.cp(
270-
['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) },
271-
File.join(download_path, 'en-US')
272-
)
211+
version = options.fetch(:version, android_get_app_version)
212+
build_number = options.fetch(:build_number, android_get_release_version['code'])
213+
214+
# If no `app:` is specified, call this for both WordPress and Jetpack
215+
apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym)
216+
217+
apps.each do |app|
218+
app_values = APP_SPECIFIC_VALUES[app]
219+
220+
version_suffix = version.split('.').join
221+
files = {
222+
"release_note_#{version_suffix}" => { desc: "changelogs/#{build_number}.txt", max_size: 500, alternate_key: "release_note_short_#{version_suffix}" },
223+
play_store_app_title: { desc: 'title.txt', max_size: 30 },
224+
play_store_promo: { desc: 'short_description.txt', max_size: 80 },
225+
play_store_desc: { desc: 'full_description.txt', max_size: 4000 }
226+
}
227+
228+
delete_old_changelogs(app: app, build: build_number)
229+
230+
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android')
231+
locales = { wordpress: WP_RELEASE_NOTES_LOCALES, jetpack: JP_RELEASE_NOTES_LOCALES }[app]
232+
UI.header("Downloading metadata translations for #{app_values[:display_name]}")
233+
gp_downloadmetadata(
234+
project_url: app_values[:glotpress_metadata_project],
235+
target_files: files,
236+
locales: locales,
237+
download_path: download_path
238+
)
273239

274-
git_add(path: download_path)
275-
git_commit(path: download_path, message: "Update Jetpack metadata translations for #{options[:version]}", allow_nothing_to_commit: true)
240+
# Copy the source `.txt` files (used as source of truth when we generated the `.po`) to the `fastlane/*metadata/android/en-US` dir,
241+
# as `en-US` is the source language, and isn't exported from GlotPress during `gp_downloadmetadata`
242+
metadata_source_dir = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir])
243+
FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{build_number}.txt"))
244+
FileUtils.cp(
245+
['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) },
246+
File.join(download_path, 'en-US')
247+
)
248+
249+
git_add(path: download_path)
250+
git_commit(path: download_path, message: "Update #{app_values[:display_name]} metadata translations for #{version}", allow_nothing_to_commit: true)
251+
end
276252
push_to_git_remote
277253
end
278254

fastlane/lanes/release.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
def get_app_name_option!(options)
315315
app = options[:app]&.downcase
316316
UI.user_error!("Missing 'app' parameter. Expected 'app:wordpress' or 'app:jetpack'") if app.nil?
317-
unless ['wordpress', 'jetpack'].include?(app)
317+
unless %i[wordpress jetpack].include?(app.to_sym)
318318
UI.user_error!("Invalid 'app' parameter #{app.inspect}. Expected 'wordpress' or 'jetpack'")
319319
end
320320
return app

0 commit comments

Comments
 (0)