Skip to content

Commit 8316911

Browse files
JeansBoussierladaapp
authored andcommitted
translations: Implement --release arg for the translation compilation scripts
1 parent 2fa4d96 commit 8316911

File tree

7 files changed

+88
-7
lines changed

7 files changed

+88
-7
lines changed

docs/windows_install.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ This section describes how to install the app (CLI and GUI) from source.
33

44
> [!NOTE]
55
> This is the Windows guide. If you're on Linux (or want to use WSL) follow the [Linux Installation](linux_install.md).
6-
> There is no native Windows pacakge yet, but you may be interested in the [Docker Image](../README.md#installation).
76
87
1) Download and install system dependencies
98

packaging/docker/Dockerfile.Latest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN apt-get update \
88
&& rm -rf /var/lib/apt/lists/*
99
RUN pip install --no-deps --no-cache-dir --requirement https://codeberg.org/ladaapp/lada/raw/main/packaging/requirements-cli.txt
1010
RUN curl -Ls https://codeberg.org/ladaapp/lada/archive/main.tar.gz | tar -zx \
11-
&& sh lada/translations/compile_po.sh zh_CN \
11+
&& sh lada/translations/compile_po.sh --release \
1212
&& pip install --no-deps --no-cache-dir './lada[basicvsrpp]' \
1313
&& patch -u -p4 -d /usr/local/lib/python3.13 < lada/patches/increase_mms_time_limit.patch \
1414
&& patch -u -p4 -d /usr/local/lib/python3.13 < lada/patches/remove_ultralytics_telemetry.patch \

packaging/windows/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Invoke-WebRequest 'https://huggingface.co/ladaapp/lada/resolve/main/lada_mosaic_
3838
Invoke-WebRequest 'https://huggingface.co/ladaapp/lada/resolve/main/lada_mosaic_restoration_model_generic_v1.2.pth?download=true' -OutFile ".\model_weights\lada_mosaic_restoration_model_generic_v1.2.pth"
3939
Invoke-WebRequest 'https://drive.usercontent.google.com/download?id=1ulct4RhRxQp1v5xwEmUH7xz7AK42Oqlw&export=download&confirm=t' -OutFile ".\model_weights\3rd_party\clean_youknow_video.pth"
4040
41-
powershell .\translations/compile_po.ps1
41+
powershell .\translations/compile_po.ps1 --release
4242
```
4343

4444
Just do a quick test `lada`, drop in a video and see if it loads. If all looks good lets continue and create a package:

translations/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Use either `compile_po.ps1` or `compile_po.sh` to compile translations.
2+
3+
If run without additional arguments all .po files will be compiled.
4+
5+
To only compile translations that should land in a release run the script with `--release` argument.
6+
7+
This will only consider translations contained in the file `release_ready_translations.txt` (single line, lang codes separated by spaces)
8+
9+
Only if quality and completeness of a translation is good enough it should be added to that file.

translations/compile_po.ps1

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
952
Get-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+
}

translations/compile_po.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ if [ "$(pwd)" != "$translations_dir" ] ; then
88
cd "$translations_dir"
99
fi
1010

11-
lang_filter="$@"
11+
lang_filter=""
12+
if [[ "$@" =~ "--release" ]]; then
13+
lang_filter=$(cat release_ready_translations.txt | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
14+
if [[ -z "$lang filter" ]]; then
15+
echo "No translations in release_ready_translations.txt"
16+
exit 1
17+
fi
18+
fi
1219

1320
function should_compile_po() {
1421
lang="$1"
@@ -23,9 +30,23 @@ function should_compile_po() {
2330
return 1
2431
}
2532

33+
# Clean up compiled translations if there is no corresponding .po file anymore (deleted translations)
34+
find ../lada/locale/ -mindepth 2 -maxdepth 2 -type d -name LC_MESSAGES | while read lang_dir; do
35+
lang=$(basename "$(dirname "$lang_dir")")
36+
po_file="$lang.po"
37+
if [ ! -f "$po_file" ]; then
38+
rm -rf "$(dirname $lang_dir)"
39+
fi
40+
done
41+
42+
# Compile .po files
2643
find . -mindepth 1 -maxdepth 1 -type f -name "*.po" -printf '%f\n' | while read po_file ; do
2744
lang="${po_file%.po}"
28-
should_compile_po $lang || continue
45+
if ! should_compile_po $lang ; then
46+
_lang_dir="../lada/locale/$lang"
47+
[ -d "$_lang_dir" ] && rm -r "$_lang_dir"
48+
continue
49+
fi
2950
lang_dir="../lada/locale/$lang/LC_MESSAGES"
3051
if [ ! -d "$lang_dir" ] ; then
3152
mkdir -p "$lang_dir"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zh_CN

0 commit comments

Comments
 (0)