@@ -6,15 +6,66 @@ if ((Get-Location).Path -ne $translationsDir) {
66 Set-Location $translationsDir
77}
88
9+ $global :lang_filter = " "
10+ if ($args -contains " --release" ) {
11+ $global :lang_filter = (Get-Content .\release_ready_translations.txt - Raw).Trim()
12+ if ($global :lang_filter -eq " " ) {
13+ Write-Host " No translations in .\release_ready_translations.txt"
14+ return
15+ }
16+ }
17+
18+ function should_compile_po {
19+ param (
20+ [string ]$lang
21+ )
22+
23+ if (-not $global :lang_filter ) {
24+ return $true
25+ }
26+
27+ foreach ($filter_lang in $global :lang_filter ) {
28+ if ($filter_lang -eq $lang ) {
29+ return $true
30+ }
31+ }
32+
33+ return $false
34+ }
35+
36+ # Clean up compiled translations if there is no corresponding .po file anymore (deleted translations)
37+ Get-ChildItem - Directory - Path ..\lada\locale | ForEach-Object {
38+ $langDir = $_.FullName
39+ $lang = $_.Name
40+
41+ $poFile = " $lang .po"
42+ if (-not (Test-Path $poFile )) {
43+ $lcMessagesDir = Join-Path $langDir " LC_MESSAGES"
44+ if (Test-Path $lcMessagesDir ) {
45+ Write-Host " Removing outdated compiled translations for language '$lang ' at '$langDir '"
46+ Remove-Item - Path $langDir - Recurse - Force
47+ }
48+ }
49+ }
50+
51+ # Compile .po files
952Get-ChildItem - File - Filter " *.po" | ForEach-Object {
1053 $poFile = $_.Name
1154 $lang = $poFile -replace " \.po$"
1255
56+ if (-not (should_compile_po $lang )) {
57+ $_langDir = " ..\lada\locale\$lang "
58+ if (Test-Path $_langDir ) {
59+ Remove-Item - Path $_langDir - Recurse - Force
60+ }
61+ return # actually a continue in a ForEach-Object loop
62+ }
63+
1364 $langDir = " ..\lada\locale\$lang \LC_MESSAGES"
1465 if (-not (Test-Path - Path $langDir )) {
15- New-Item - ItemType Directory - Path $langDir - Force
66+ New-Item - ItemType Directory - Path $langDir - Force | Out-Null
1667 }
1768
1869 Write-Host " Compiling language '$lang ' .po file into .mo file"
1970 & msgfmt $poFile - o " $langDir \lada.mo"
20- }
71+ }
0 commit comments