@@ -23,15 +23,17 @@ if (Test-Path $mdFile) {
2323 try {
2424 Copy-Item " $addonId .xliff" $tempXliff - Force
2525 Write-Host " DEBUG: Updating XLIFF source based on readme.md..."
26- uv run .github/ scripts/ markdownTranslate.py updateXliff - m $mdFile - x $tempXliff - o $xliffFile
27- } finally {
26+ ./ l10nUtil.exe md2xliff $mdFile $xliffFile - o $tempXliff
27+ }
28+ finally {
2829 if (Test-Path $tempXliff ) {
2930 Remove-Item $tempXliff - Force
3031 }
3132 }
32- } else {
33+ }
34+ else {
3335 Write-Host " DEBUG: XLIFF template not found. Creating new one from readme.md..."
34- uv run .github / scripts / markdownTranslate.py generateXliff - m $mdFile - o $xliffFile
36+ . / l10nUtil.exe md2xliff $mdFile $xliffFile
3537 }
3638}
3739
@@ -43,24 +45,25 @@ $potFile = "$addonId.pot"
4345
4446if (Test-Path $potFile ) {
4547 Write-Host " DEBUG: Uploading updated POT source to Crowdin..."
46- ./ l10nUtil.exe uploadSourceFile " $potFile " - c addon
48+ ./ l10nUtil.exe uploadSourceFile " $potFile " - c $ env: L10N_UTIL_CONFIG
4749}
4850
4951if (Test-Path $xliffFile ) {
5052 Write-Host " DEBUG: Uploading updated XLIFF source to Crowdin..."
51- ./ l10nUtil.exe uploadSourceFile " $xliffFile " - c addon
53+ ./ l10nUtil.exe uploadSourceFile " $xliffFile " - c $env: L10N_UTIL_CONFIG
54+
5255 git add " $xliffFile "
5356 git diff -- staged -- quiet
57+
5458 if ($LASTEXITCODE -ne 0 ) {
5559 git commit - m " Update $xliffFile for $addonId "
56- git push
5760 }
5861}
5962
6063# --- STEP 3: EXPORT AND PROCESS TRANSLATIONS ---
6164
6265Write-Host " DEBUG: Exporting translations from Crowdin..."
63- ./ l10nUtil.exe exportTranslations - o _addonL10n - c addon
66+ ./ l10nUtil.exe exportTranslations - o _addonL10n - c $ env: L10N_UTIL_CONFIG
6467
6568# Ensure base directories exist
6669New-Item - ItemType Directory - Force - Path addon/ locale | Out-Null
@@ -70,111 +73,155 @@ New-Item -ItemType Directory -Force -Path addon/doc | Out-Null
7073$languageMappings = Get-Content - Raw " .github/scripts/languageMappings.json" | ConvertFrom-Json
7174
7275foreach ($dir in Get-ChildItem - Path " _addonL10n/$addonId " - Directory) {
76+
7377 $langCode = $dir.Name
7478
75- if ($langCode -eq " en" ) { continue }
79+ if ($langCode -eq " en" ) {
80+ continue
81+ }
7682
7783 # --- Identify codes
84+
7885 $crowdinLang = $null
7986
80- # Use the ."variable" syntax to correctly read the PSCustomObject from JSON
8187 if ($languageMappings.PSObject.Properties.Name -contains $langCode ) {
8288 $crowdinLang = $languageMappings ." $langCode "
8389 }
8490
85- # Fallback: If no mapping is found, replace underscores with dashes for Crowdin compatibility
8691 if (-not $crowdinLang ) {
8792 $crowdinLang = $langCode.Replace (' _' , ' -' )
8893 }
8994
90- # The $langCode (folder name from Crowdin) represents the local repository language code.
91- # It matches the NVDA directory structure, so no extra mapping is needed.
9295 Write-Host " --- Processing Language: $langCode (Crowdin: $crowdinLang ) ---" - ForegroundColor Cyan
9396
9497 # Paths
95- $remoteMd = Join-Path $dir .FullName " $addonId .md "
98+
9699 $remoteXliff = Join-Path $dir.FullName " $addonId .xliff"
97100 $remotePo = Join-Path $dir.FullName " $addonId .po"
101+
98102 $localMdDir = " addon/doc/$langCode "
99103 $localMd = " $localMdDir /readme.md"
104+
100105 $localPoPath = " addon/locale/$langCode /LC_MESSAGES/nvda.po"
101106
102107 # --- 3.1 PO FILE PROCESSING ---
103108 $poImported = $false
109+ $scorePo = 0.0
110+ $threshold = $env: MIN_PERCENTAGE_TRANSLATED
111+
104112 if (Test-Path $remotePo ) {
105- Write-Host " DEBUG: Checking Remote PO progress for $crowdinLang ..."
106- uv run python .github/ scripts/ checkTranslation.py " $addonId .po" $crowdinLang
107- if ($LASTEXITCODE -eq 0 ) {
108- Write-Host " SUCCESS: Remote PO is valid. Importing to $localPoPath "
113+
114+ Write-Host " DEBUG: Evaluating Remote PO score..."
115+
116+ $res = uv run python .github/ scripts/ checkTranslation.py " $addonId .po" $crowdinLang
117+
118+ $scorePo = [double ](
119+ ($res | Select-String " poScore=" ).ToString().Split(" =" )[1 ]
120+ )
121+
122+ Write-Host " DEBUG: PO Score -> $scorePo "
123+
124+ if ($scorePo -ge $threshold ) {
125+
126+ Write-Host " SUCCESS: Remote PO is above threshold. Importing to $localPoPath "
127+
109128 New-Item - ItemType Directory - Force - Path (Split-Path $localPoPath ) | Out-Null
129+
110130 Move-Item $remotePo $localPoPath - Force
131+
111132 $poImported = $true
112- } else {
113- Write-Host " WARNING: Remote PO progress is below threshold."
133+ }
134+ else {
135+
136+ Write-Host " WARNING: Remote PO score is below threshold ($threshold )."
114137 }
115138 }
116139
117140 if (-not $poImported -and (Test-Path $localPoPath )) {
141+
118142 Write-Host " ACTION: Uploading local legacy PO to Crowdin ($crowdinLang ) as fallback."
119- ./ l10nUtil.exe uploadTranslationFile $crowdinLang " $addonId .po" $localPoPath - c addon
143+
144+ ./ l10nUtil.exe uploadTranslationFile $crowdinLang " $addonId .po" $localPoPath - c $env: L10N_UTIL_CONFIG
120145 }
121146
122- # --- 3.2 DOCUMENTATION PROCESSING (MD & XLIFF) ---
123- $scoreMd = 0.0
124- $scoreXliff = 0.0
147+ # --- 3.2 DOCUMENTATION PROCESSING (XLIFF ONLY) ---
125148
126- if (Test-Path $remoteMd ) {
127- Write-Host " DEBUG: Evaluating Remote Markdown score..."
128- $res = uv run python .github/ scripts/ checkTranslation.py " $addonId .md" $crowdinLang
129- $scoreMd = [double ]($res | Select-String " mdScore=" ).ToString().Split(" =" )[1 ]
130- } else {
131- Write-Host " DEBUG: No remote Markdown file found for this language."
132- }
149+ $scoreXliff = 0.0
133150
134151 if (Test-Path $remoteXliff ) {
152+
135153 Write-Host " DEBUG: Evaluating Remote XLIFF score..."
154+
136155 $res = uv run python .github/ scripts/ checkTranslation.py " $addonId .xliff" $crowdinLang
137- $scoreXliff = [double ]($res | Select-String " xliffScore=" ).ToString().Split(" =" )[1 ]
138- } else {
156+
157+ $scoreXliff = [double ](
158+ ($res | Select-String " xliffScore=" ).ToString().Split(" =" )[1 ]
159+ )
160+ }
161+ else {
139162 Write-Host " DEBUG: No remote XLIFF file found for this language."
140163 }
141164
142- Write-Host " DEBUG: Comparison Scores -> MD: $scoreMd | XLIFF: $scoreXliff "
165+ Write-Host " DEBUG: XLIFF Score -> $scoreXliff "
143166
144- $threshold = 0.5
167+ $threshold = $ env: MIN_PERCENTAGE_TRANSLATED
145168 $docImported = $false
146169
147- if ($scoreXliff -gt $threshold -or $scoreMd -gt $threshold ) {
148- if (! (Test-Path $localMdDir )) { New-Item - ItemType Directory - Force - Path $localMdDir | Out-Null }
149-
150- if ($scoreXliff -ge $scoreMd ) {
151- Write-Host " SUCCESS: XLIFF is better or equal. Converting XLIFF to local MD ($langCode )..."
152- ./ l10nUtil.exe xliff2md $remoteXliff $localMd
153- $docImported = $true
154- } else {
155- Write-Host " SUCCESS: Markdown is better. Importing Remote MD to local ($langCode )..."
156- Move-Item $remoteMd $localMd - Force
157- $docImported = $true
170+ if ($scoreXliff -ge $threshold ) {
171+
172+ if (! (Test-Path $localMdDir )) {
173+ New-Item - ItemType Directory - Force - Path $localMdDir | Out-Null
158174 }
159- } else {
160- Write-Host " WARNING: Both remote MD and XLIFF scores are below threshold ($threshold )."
175+
176+ Write-Host " SUCCESS: Importing documentation from XLIFF ($langCode )..."
177+
178+ ./ l10nUtil.exe xliff2md $remoteXliff $localMd
179+
180+ $docImported = $true
161181 }
182+ else {
162183
163- if (-not $docImported -and (Test-Path $localMd )) {
164- Write-Host " ACTION: Documentation quality too low. Uploading local MD to Crowdin ($crowdinLang ) as fallback."
165- ./ l10nUtil.exe uploadTranslationFile $crowdinLang " $addonId .md" $localMd - c addon
184+ Write-Host " WARNING: Remote XLIFF score is below threshold ($threshold )."
166185 }
186+
187+ # No Markdown fallback upload anymore.
188+ # XLIFF is now the single translation source in Crowdin.
167189}
168190
169191# --- STEP 4: COMMIT UPDATED TRANSLATIONS ---
170192
171193git add addon/ locale addon/ doc
194+
172195git diff -- staged -- quiet
196+
173197if ($LASTEXITCODE -ne 0 ) {
198+
174199 git commit - m " Update translations for $addonId from Crowdin (Automatic Sync)"
175- $branch = $env: downloadTranslationsBranch
176- git push -f origin " HEAD:$branch "
177- Write-Host " SUCCESS: Translations committed and pushed."
178- } else {
200+
201+ Write-Host " SUCCESS: Translations committed."
202+ }
203+ else {
204+
179205 Write-Host " DEBUG: No changes in translations to commit."
180206}
207+
208+ # Push all generated commits after successful Crowdin synchronization
209+
210+ $pushOutput = git push 2>&1
211+
212+ $repository = $env: GITHUB_REPOSITORY
213+
214+ Write-Host $pushOutput
215+
216+ if ($LASTEXITCODE -ne 0 ) {
217+
218+ Write-Host " ERROR: Failed to push commits to $repository ."
219+ }
220+ elseif ($pushOutput -match " Everything up-to-date" ) {
221+
222+ Write-Host " INFO: No new commits needed to be pushed."
223+ }
224+ else {
225+
226+ Write-Host " SUCCESS: New commits successfully pushed to $repository ."
227+ }
0 commit comments