|
82 | 82 | end |
83 | 83 | end |
84 | 84 |
|
85 | | - # Builds Localizable.xcstrings, the future regular-string backing store, end to end: |
86 | | - # 1. scan the code into the English catalog (generate_strings_catalog), |
87 | | - # 2. download the current GlotPress translations and fold them in (human => translated), |
88 | | - # 3. AI-fill the cells GlotPress left empty (=> needs_review) — see CatalogStrings.fold_translations!. |
89 | | - # Uploading the AI drafts back to GlotPress as needs-review for human review (the eventual "step 4") is a |
90 | | - # separate step, not done here — it builds on the existing GlotPress import integration (cf. |
91 | | - # gp_update_metadata_source). For now the machine cells live in the catalog as needs_review. |
| 85 | + # STEP 2 (download) — pull the current GlotPress translations for the given locales into their `*.lproj` dirs, |
| 86 | + # ready for `localize_catalog` to fold. A thin, scoped wrapper around the GlotPress download (the full |
| 87 | + # `download_localized_strings` works too, if you want every locale plus the plural fold). Scope with |
| 88 | + # `locales:fr,de`; default is all ship locales. Doesn't commit — the `.strings` are transient input. |
| 89 | + desc 'Download step: pull GlotPress translations into the *.lproj dirs (then run localize_catalog)' |
| 90 | + lane :download_catalog_strings do |options| |
| 91 | + locales = catalog_target_locales(options[:locales]) |
| 92 | + ios_download_strings_files_from_glotpress( |
| 93 | + project_url: GLOTPRESS_APP_STRINGS_PROJECT_URL, |
| 94 | + locales: locales, |
| 95 | + download_dir: File.join(PROJECT_ROOT_FOLDER, 'WordPress', 'Resources') |
| 96 | + ) |
| 97 | + UI.success("Downloaded GlotPress translations for #{locales.values.uniq.size} locale(s). Next: run localize_catalog (same locales:).") |
| 98 | + end |
| 99 | + |
| 100 | + # LOCALIZE (steps 1 + 3) — build Localizable.xcstrings from the ALREADY-DOWNLOADED strings: scan the code into |
| 101 | + # the English catalog, fold the GlotPress translations in (human => translated), and AI-fill the cells they |
| 102 | + # leave empty (=> needs_review). Run `download_catalog_strings` (or `download_localized_strings`) first. |
| 103 | + # |
| 104 | + # Uploading the AI drafts back to GlotPress as needs-review (the eventual "step 4") is a separate step, not |
| 105 | + # done here — it builds on the existing GlotPress import integration (cf. gp_update_metadata_source). |
92 | 106 | # |
93 | 107 | # STAGED, NOT SHIPPED: Localizable.xcstrings isn't the runtime store yet (the app still ships |
94 | 108 | # Localizable.strings), so this only pre-populates it for the cutover — it changes nothing users see. |
95 | 109 | # |
96 | | - # MANUAL ONLY — deliberately not wired into download_localized_strings or any CI step: it runs xcstringstool |
97 | | - # extraction, downloads from GlotPress, calls the translation API (cost), and commits a large catalog. Set |
98 | | - # ANTHROPIC_API_KEY for step 3; scope a cheap run with `locales:fr` (and add `skip_download:true` to reuse the |
99 | | - # committed .strings instead of re-downloading). |
100 | | - desc 'Builds Localizable.xcstrings: scan code, fold GlotPress translations, AI-fill the rest (staged; manual, not CI)' |
101 | | - lane :download_localized_catalog do |options| |
102 | | - resources_dir = File.join(PROJECT_ROOT_FOLDER, 'WordPress', 'Resources') |
103 | | - locales = catalog_target_locales(options[:locales]) # all ship locales, or the `locales:fr,de` subset |
| 110 | + # MANUAL ONLY — not wired into download_localized_strings or any CI step: it runs xcstringstool extraction, |
| 111 | + # calls the translation API (cost), and commits a large catalog. Set ANTHROPIC_API_KEY for the AI rung; scope |
| 112 | + # a cheap run with `locales:fr`. |
| 113 | + desc 'Localize step: build Localizable.xcstrings from downloaded strings — scan + fold + AI-fill (staged; manual, not CI)' |
| 114 | + lane :localize_catalog do |options| |
| 115 | + locales = catalog_target_locales(options[:locales]) |
104 | 116 |
|
105 | 117 | # 1. Scan the code into the English catalog (create / update + reconcile changed sources). |
106 | 118 | generate_strings_catalog |
107 | 119 |
|
108 | | - # 2. Download the current GlotPress translations for those locales (skip to reuse the committed .strings). |
109 | | - download_catalog_strings(resources_dir, locales) unless catalog_flag?(options[:skip_download]) |
110 | | - |
111 | | - # 2b + 3. Fold the human translations in (=> translated), then AI-fill the cells GlotPress left empty. |
| 120 | + # Fold the downloaded human translations in (=> translated), then (3) AI-fill the cells they leave empty. |
112 | 121 | catalog = JSON.parse(File.read(LOCALIZABLE_CATALOG)) |
113 | 122 | written = CatalogStrings.fold_translations!( |
114 | 123 | catalog, |
115 | | - translations_by_locale: catalog_translations_by_locale(resources_dir), |
| 124 | + translations_by_locale: catalog_translations_by_locale(File.join(PROJECT_ROOT_FOLDER, 'WordPress', 'Resources')), |
116 | 125 | locales: locales.values.uniq, |
117 | 126 | ai_translator: catalog_ai_translator |
118 | 127 | ) |
@@ -253,20 +262,6 @@ def catalog_target_locales(spec) |
253 | 262 | selected |
254 | 263 | end |
255 | 264 |
|
256 | | - # Step 2: download the current GlotPress translations for the given locales into their `*.lproj` dirs. |
257 | | - def download_catalog_strings(resources_dir, locales) |
258 | | - ios_download_strings_files_from_glotpress( |
259 | | - project_url: GLOTPRESS_APP_STRINGS_PROJECT_URL, |
260 | | - locales: locales, |
261 | | - download_dir: resources_dir |
262 | | - ) |
263 | | - end |
264 | | - |
265 | | - # A fastlane CLI flag, which arrives as a string ("true"/"1"/"yes") or a real boolean. |
266 | | - def catalog_flag?(value) |
267 | | - %w[true 1 yes].include?(value.to_s.strip.downcase) |
268 | | - end |
269 | | - |
270 | 265 | # { lproj => { key => human value } } from the downloaded translation `.strings`. The flat plural keys present |
271 | 266 | # in these files aren't catalog keys, so the fold ignores them (they belong to Plurals.xcstrings). |
272 | 267 | def catalog_translations_by_locale(dir) |
|
0 commit comments