Skip to content

Commit b2f42aa

Browse files
authored
Merge pull request #17341 from wordpress-mobile/tooling/fix-enUS-enGB-hack
[Tooling] Fix issue with en-US release notes not generated if en-GB was not translated
2 parents 0b05d81 + 43783c2 commit b2f42aa

File tree

3 files changed

+72
-136
lines changed

3 files changed

+72
-136
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: 69 additions & 135 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: {} },
@@ -95,78 +94,36 @@
9594
#####################################################################################
9695
desc 'Updates the PlayStoreStrings.po files for WP + JP'
9796
lane :update_appstore_strings do |options|
98-
update_wordpress_appstore_strings(options)
99-
update_jetpack_appstore_strings(options)
100-
end
101-
102-
#####################################################################################
103-
# update_wordpress_appstore_strings
104-
# -----------------------------------------------------------------------------------
105-
# This lane gets the data from the txt files in the `WordPress/metadata/` folder
106-
# and updates the `.po` file that is then picked by GlotPress for translations.
107-
# -----------------------------------------------------------------------------------
108-
# Usage:
109-
# fastlane update_wordpress_appstore_strings [version:<version>]
110-
#
111-
# Example:
112-
# fastlane update_wordpress_appstore_strings version:10.3
113-
#####################################################################################
114-
desc 'Updates the PlayStoreStrings.po file for WordPress'
115-
lane :update_wordpress_appstore_strings do |options|
116-
metadata_folder = File.join(Dir.pwd, '..', 'WordPress', 'metadata')
117-
version = options.fetch(:version, android_get_app_version)
118-
119-
# <key in po file> => <path to txt file to read the content from>
120-
files = {
121-
release_note: File.join(metadata_folder, 'release_notes.txt'),
122-
release_note_short: File.join(metadata_folder, 'release_notes_short.txt'),
123-
play_store_app_title: File.join(metadata_folder, 'title.txt'),
124-
play_store_promo: File.join(metadata_folder, 'short_description.txt'),
125-
play_store_desc: File.join(metadata_folder, 'full_description.txt')
126-
}
127-
files.merge!((1..9).map do |n|
128-
[:"play_store_screenshot_#{n}", File.join(metadata_folder, "screenshot_#{n}.txt")]
129-
end.to_h)
130-
131-
update_po_file_for_metadata_localization(
132-
po_path: File.join(metadata_folder, 'PlayStoreStrings.po'),
133-
sources: files,
134-
release_version: version,
135-
commit_message: "Update WordPress `PlayStoreStrings.po` for version #{version}"
136-
)
137-
end
138-
139-
#####################################################################################
140-
# update_jetpack_appstore_strings
141-
# -----------------------------------------------------------------------------------
142-
# This lane gets the data from the txt files in the `WordPress/jetpack_metadata/` folder
143-
# and updates the `.po` file that is then picked by GlotPress for translations.
144-
# -----------------------------------------------------------------------------------
145-
# Usage:
146-
# fastlane update_jetpack_appstore_strings [version:<version>]
147-
#
148-
# Example:
149-
# fastlane update_jetpack_appstore_strings version:10.3
150-
#####################################################################################
151-
desc 'Updates the PlayStoreStrings.po file for Jetpack'
152-
lane :update_jetpack_appstore_strings do |options|
153-
metadata_folder = File.join(Dir.pwd, '..', 'WordPress', 'jetpack_metadata')
154-
version = options.fetch(:version, android_get_app_version)
97+
# If no `app:` is specified, call this for both WordPress and Jetpack
98+
apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym)
99+
100+
apps.each do |app|
101+
app_values = APP_SPECIFIC_VALUES[app]
102+
103+
metadata_folder = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir])
104+
version = options.fetch(:version, android_get_app_version)
105+
106+
# <key in po file> => <path to txt file to read the content from>
107+
files = {
108+
release_note: File.join(metadata_folder, 'release_notes.txt'),
109+
release_note_short: File.join(metadata_folder, 'release_notes_short.txt'),
110+
play_store_app_title: File.join(metadata_folder, 'title.txt'),
111+
play_store_promo: File.join(metadata_folder, 'short_description.txt'),
112+
play_store_desc: File.join(metadata_folder, 'full_description.txt')
113+
}
114+
# Add entries for `screenshot_*.txt` files as well
115+
Dir.glob('screenshot_*.txt', base: metadata_folder).sort.each do |screenshot_file|
116+
key = "play_store_#{File.basename(screenshot_file, '.txt')}".to_sym
117+
files[key] = File.join(metadata_folder, screenshot_file)
118+
end
155119

156-
files = {
157-
release_note: File.join(metadata_folder, 'release_notes.txt'),
158-
release_note_short: File.join(metadata_folder, 'release_notes_short.txt'),
159-
play_store_app_title: File.join(metadata_folder, 'title.txt'),
160-
play_store_promo: File.join(metadata_folder, 'short_description.txt'),
161-
play_store_desc: File.join(metadata_folder, 'full_description.txt')
162-
}
163-
164-
update_po_file_for_metadata_localization(
165-
po_path: File.join(metadata_folder, 'PlayStoreStrings.po'),
166-
sources: files,
167-
release_version: version,
168-
commit_message: "Update Jetpack `PlayStoreStrings.po` for version #{version}"
169-
)
120+
update_po_file_for_metadata_localization(
121+
po_path: File.join(metadata_folder, 'PlayStoreStrings.po'),
122+
sources: files,
123+
release_version: version,
124+
commit_message: "Update #{app_values[:display_name]} `PlayStoreStrings.po` for version #{version}"
125+
)
126+
end
170127
end
171128

172129
# 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 @@
209166
#####################################################################################
210167
desc 'Downloads translated metadata from GlotPress'
211168
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-
)
169+
version = options.fetch(:version, android_get_app_version)
170+
build_number = options.fetch(:build_number, android_get_release_version['code'])
171+
172+
# If no `app:` is specified, call this for both WordPress and Jetpack
173+
apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym)
174+
175+
apps.each do |app|
176+
app_values = APP_SPECIFIC_VALUES[app]
177+
178+
version_suffix = version.split('.').join
179+
files = {
180+
"release_note_#{version_suffix}" => { desc: "changelogs/#{build_number}.txt", max_size: 500, alternate_key: "release_note_short_#{version_suffix}" },
181+
play_store_app_title: { desc: 'title.txt', max_size: 30 },
182+
play_store_promo: { desc: 'short_description.txt', max_size: 80 },
183+
play_store_desc: { desc: 'full_description.txt', max_size: 4000 }
184+
}
185+
186+
delete_old_changelogs(app: app, build: build_number)
187+
188+
download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android')
189+
locales = { wordpress: WP_RELEASE_NOTES_LOCALES, jetpack: JP_RELEASE_NOTES_LOCALES }[app]
190+
UI.header("Downloading metadata translations for #{app_values[:display_name]}")
191+
gp_downloadmetadata(
192+
project_url: app_values[:glotpress_metadata_project],
193+
target_files: files,
194+
locales: locales,
195+
download_path: download_path
196+
)
273197

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)
198+
# Copy the source `.txt` files (used as source of truth when we generated the `.po`) to the `fastlane/*metadata/android/en-US` dir,
199+
# as `en-US` is the source language, and isn't exported from GlotPress during `gp_downloadmetadata`
200+
metadata_source_dir = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir])
201+
FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{build_number}.txt"))
202+
FileUtils.cp(
203+
['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) },
204+
File.join(download_path, 'en-US')
205+
)
206+
207+
git_add(path: download_path)
208+
git_commit(path: download_path, message: "Update #{app_values[:display_name]} metadata translations for #{version}", allow_nothing_to_commit: true)
209+
end
276210
push_to_git_remote
277211
end
278212

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)