@@ -4,6 +4,8 @@ fastlane_require 'digest'
44fastlane_require 'zip'
55fastlane_require 'aws-sdk-cloudfront'
66fastlane_require 'json'
7+ fastlane_require 'net/http'
8+ fastlane_require 'uri'
79
810UI . user_error! ( 'Please run fastlane via `bundle exec`' ) unless FastlaneCore ::Helper . bundler?
911
@@ -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)
2830POT_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+
3036APPLE_TEAM_ID = 'PZYM8XX95Q'
3137APPLE_BUNDLE_IDENTIFIER = 'com.automattic.studio'
3238APPLE_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 } " )
346352end
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