Skip to content

Commit eead492

Browse files
authored
Merge pull request #90 from nvdaes/updateTemplate
Update template with NVDA addon migrator from @abdel792
2 parents 99d9eb2 + 7db9100 commit eead492

39 files changed

Lines changed: 600 additions & 304 deletions

.github/scripts/checkTranslation.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# checkTranslation.py
21
# Copyright (C) 2026 NV Access Limited, Abdel
32
# This file is covered by the GNU General Public License.
43
# See the file COPYING for more details.
@@ -101,7 +100,7 @@ def getScoreFromApi(fileNameToSearch: str, langId: str) -> float:
101100
# Also handles underscore to dash conversion for Crowdin compatibility
102101
if langApi.lower().startswith(langId.lower().replace("_", "-")):
103102
progress = float(item["data"]["translationProgress"])
104-
return progress / 100
103+
return progress
105104

106105
# Check pagination total.
107106
total = resp["pagination"]["totalCount"]
@@ -140,9 +139,6 @@ def main():
140139
# Default to poScore for .po and other localization files.
141140
print(f"poScore={score}")
142141

143-
# Exit with success (0) if there is at least 50% translated content.
144-
sys.exit(0 if score > 0.5 else 1)
145-
146142

147143
if __name__ == "__main__":
148144
main()

.github/scripts/crowdinSync.ps1

Lines changed: 102 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4446
if (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

4951
if (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

6265
Write-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
6669
New-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

7275
foreach ($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

171193
git add addon/locale addon/doc
194+
172195
git diff --staged --quiet
196+
173197
if ($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+
}

.github/scripts/languageMappings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"es": "es-ES",
55
"es_CO": "es-CO",
66
"nb_NO": "nb",
7+
"ne": "ne-NP",
78
"nn_NO": "nn-NO",
89
"pt_PT": "pt-PT",
910
"pt_BR": "pt-BR",

.github/scripts/setOutputs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# setOutputs.py
2-
# Copyright (C) 2025 NV Access Limited, Noelia Ruiz Martínez
1+
# Copyright (C) 2025-2026 NV Access Limited, Noelia Ruiz Martínez
32
# This file is covered by the GNU General Public License.
43
# See the file COPYING for more details.
54

.github/workflows/build_addon.yml

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)