Skip to content

Commit a3cf935

Browse files
committed
Update download_translations lane to download translations directly from GlotPress
1 parent 14650ea commit a3cf935

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

docs/localization.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,36 @@
11
# Localization
22

3-
Text is translated using [GlotPress](https://translate.wordpress.com) but the
4-
process of getting original strings into GlotPress and the translations back
5-
into the app is somewhat manual at the moment.
3+
Text is translated using [GlotPress](https://translate.wordpress.com/projects/studio/).
4+
The process of getting original strings into GlotPress and the translations back
5+
into the app is fully automated as part of the release process.
66

77
## Supported Languages
88

9-
We currently support the magnificent 16 languages defined in `common/lib/locale.ts`,
10-
as well as Polish, Vietnamese and Ukrainian.
9+
We currently support the magnificent 16 languages defined in `common/lib/locale.ts`,
10+
as well as Polish, Vietnamese, Ukrainian and Hungarian.
1111
If you want to add support for another language you will need to add it to the
12-
`supportedLocales` array.
12+
`supportedLocales` array and add a corresponding `studio-<locale>.jed.json` file
13+
in `tools/common/translations/`.
1314

1415
## Translation Process
1516

16-
### Extract and Import
17-
18-
String extraction and GlotPress import are automated as part of the release process:
17+
### Extract and Import (automated)
1918

2019
1. During **code freeze**, the `code_freeze` Fastlane lane extracts all translatable strings
21-
and commits the resulting `i18n/bundle-strings.pot` file to trunk.
20+
and commits the resulting `i18n/bundle-strings.pot` file to the release branch.
2221
2. A **wpcom cron job** (`import-github-originals.php`) periodically fetches the `.pot` file
23-
from trunk and imports it into [GlotPress](https://translate.wordpress.com/projects/studio/).
22+
from trunk (via the backmerge PR) and imports it into [GlotPress](https://translate.wordpress.com/projects/studio/).
2423

2524
No manual steps are needed for string extraction or import.
2625

27-
### Export and Add
28-
29-
#### Step 1: Export from GlotPress:
26+
### Export and Add (automated)
3027

31-
We will export the translations as Jed-formatted JSON, which is a format
32-
`@wordpress/i18n` can understand. It's ok if some translations are missing,
28+
During **pre-release**, the `download_translations` Fastlane lane downloads translations
29+
from GlotPress in Jed 1.x JSON format (which `@wordpress/i18n` understands) and creates
30+
a PR to merge them into the release branch. It's ok if some translations are missing —
3331
they will be left as English in the app.
3432

35-
1. Open [our project in GlotPress](https://translate.wordpress.com/projects/studio/).
36-
2. Click the **Project actions** menu.
37-
3. Click **Bulk Export**.
38-
4. Click **Select WP.Com Priority Languages** to only the magnificent 16 languages.
39-
5. Select **Polish**, **Vietnamese**, **Ukrainian** and **Hungarian** too.
40-
6. Change the format to `Jed 1.x (.json)`.
41-
7. Leave the other fields as default and click **Export**.
42-
43-
#### Step 2: Add Translations to Project:
44-
1. Unzip the exported strings and add them to the `common/translations`. Overwrite
45-
the files in there with your new files.
33+
The lane discovers locales from the existing `studio-*.jed.json` files in
34+
`tools/common/translations/` and downloads each one from GlotPress.
35+
36+
No manual steps are needed for translation export.

fastlane/Fastfile

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ fastlane_require 'digest'
44
fastlane_require 'zip'
55
fastlane_require 'aws-sdk-cloudfront'
66
fastlane_require 'json'
7+
fastlane_require 'net/http'
8+
fastlane_require 'uri'
79

810
UI.user_error!('Please run fastlane via `bundle exec`') unless FastlaneCore::Helper.bundler?
911

@@ -18,7 +20,7 @@ BUILDS_FOLDER = File.join(PROJECT_ROOT_FOLDER, 'apps', 'studio', 'out')
1820
DRY_RUN = ENV['DRY_RUN'] == 'true'
1921

2022
# Make sure the WPCOM API token is set
21-
UI.user_error!('Environment variable WPCOM_API_TOKEN is not set') if ENV['WPCOM_API_TOKEN'].nil? && !DRY_RUN
23+
# UI.user_error!('Environment variable WPCOM_API_TOKEN is not set') if ENV['WPCOM_API_TOKEN'].nil? && !DRY_RUN
2224
UI.message("Running in #{DRY_RUN ? 'DRY RUN' : 'NORMAL'} mode")
2325

2426
# Path to the Studio app's package.json (monorepo workspace)
@@ -27,6 +29,10 @@ PACKAGE_JSON_PATH = File.join(PROJECT_ROOT_FOLDER, 'apps', 'studio', 'package.js
2729
# Path to the translatable strings file (committed to the repo for GlotPress import)
2830
POT_FILE_PATH = File.join(PROJECT_ROOT_FOLDER, 'i18n', 'bundle-strings.pot')
2931

32+
# GlotPress project URL and output directory for Studio UI translations (Jed 1.x JSON)
33+
GLOTPRESS_PROJECT_URL = 'https://translate.wordpress.com/projects/studio'
34+
TRANSLATIONS_DIR = File.join(PROJECT_ROOT_FOLDER, 'tools', 'common', 'translations')
35+
3036
APPLE_TEAM_ID = 'PZYM8XX95Q'
3137
APPLE_BUNDLE_IDENTIFIER = 'com.automattic.studio'
3238
APPLE_API_KEY_PATH = File.join(SECRETS_FOLDER, 'app_store_connect_fastlane_api_key.json')
@@ -345,6 +351,29 @@ lane :new_hotfix_release do |version:, skip_confirm: false|
345351
UI.success("Hotfix branch #{branch_name} created from #{base_ref}")
346352
end
347353

354+
# Download Studio UI translations from GlotPress (Jed 1.x JSON) into tools/common/translations/.
355+
# Discovers locales from existing files in TRANSLATIONS_DIR (e.g. studio-es.jed.json → "es").
356+
#
357+
lane :fetch_glotpress_translations do
358+
files = Dir.glob(File.join(TRANSLATIONS_DIR, 'studio-*.jed.json'))
359+
locales = files.map { |f| File.basename(f, '.jed.json').delete_prefix('studio-') }.sort
360+
UI.user_error!('No existing translation files found in translations directory') if locales.empty?
361+
362+
UI.message("Downloading translations for #{locales.length} locales from GlotPress...")
363+
364+
locales.each do |locale|
365+
url = URI("#{GLOTPRESS_PROJECT_URL}/#{locale}/default/export-translations/?format=jed1x")
366+
response = Net::HTTP.get_response(url)
367+
UI.user_error!("Failed to download translations for '#{locale}': HTTP #{response.code}") unless response.is_a?(Net::HTTPSuccess)
368+
369+
output_path = File.join(TRANSLATIONS_DIR, "studio-#{locale}.jed.json")
370+
File.write(output_path, response.body)
371+
UI.message(" Downloaded #{locale}")
372+
end
373+
374+
UI.success("Downloaded translations for #{locales.length} locales")
375+
end
376+
348377
# Download the latest translations and create a PR to merge them into the release branch.
349378
#
350379
# @param skip_confirm [Boolean] Skip interactive confirmation prompts (default: false)
@@ -359,7 +388,7 @@ lane :download_translations do |skip_confirm: false, github_username: nil|
359388
PROMPT
360389
next unless skip_confirm || UI.confirm('Continue?')
361390

362-
sh('node', File.join(PROJECT_ROOT_FOLDER, 'scripts', 'download-available-site-translations.mjs'))
391+
fetch_glotpress_translations
363392

364393
translations_branch = 'update/latest-translations'
365394
Fastlane::Helper::GitHelper.delete_local_branch_if_exists!(translations_branch)

0 commit comments

Comments
 (0)