Import manual translations with GPT (#1037)

Save prompt for proper input format.
This commit is contained in:
Davide 2024-12-22 10:10:54 +01:00 committed by GitHub
parent 2ae615406a
commit a187fd56e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 84 additions and 0 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ fastlane/**/trade_representative_contact_information
build/ build/
dist/ dist/
/iap/ /iap/
/l10n/
screenshots/html/*/0*.png screenshots/html/*/0*.png
screenshots/results/ screenshots/results/
/templates/ /templates/

View File

@ -8,3 +8,5 @@ api_git="https://github.com/passepartoutvpn/api"
api_version="v5" api_version="v5"
api_path=".api" api_path=".api"
api_package_path="Library/Sources/CommonAPI/API" api_package_path="Library/Sources/CommonAPI/API"
translations_input_path="l10n"
translations_output_path="Library/Sources/UILibrary/Resources"

55
scripts/import-translations.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
cwd=`dirname $0`
source $cwd/env.sh
cd $cwd/..
if [[ -z "$1" ]]; then
echo "Input strings file required"
exit 1
fi
translations=`cat "$1"`
mkdir -p "$translations_input_path"
# Split translations into separate files
echo "$translations" | awk -v input_path="$translations_input_path" '
BEGIN {
lang_code = "";
}
/^\/\/ [a-z]{2}/ {
# Save the language code from lines starting with "//"
lang_code = substr($0, 4); # Extract language code (e.g., "de")
next;
}
/^$/ {
# Skip empty lines
next;
}
{
# Write to the appropriate language file
if (lang_code != "") {
file_path = input_path "/" lang_code;
print $0 >> file_path;
}
}
' "$1"
echo "Files have been created in the '$translations_input_path' directory."
for lang in `ls $translations_input_path`; do
input_path="$translations_input_path/$lang"
output_path="$translations_output_path/$lang.lproj/Localizable.strings"
keys_path="$output_path.keys"
tmp_path="$output_path.tmp"
# remove keys
sed -E 's/^"(.*)" = .*$/\1/' $input_path >$keys_path
grep -vf $keys_path $output_path >$tmp_path
# append new strings
cat $input_path >>$tmp_path
# sort and replace
sort $tmp_path | uniq >$output_path
rm "$keys_path" "$tmp_path"
done

View File

@ -0,0 +1,26 @@
I need translations in the following languages:
- German
- Greek
- Spanish
- French
- Italian
- Dutch
- Polish
- Portuguese
- Russian
- Swedish
- Ukranian
- Chinese (Simplified)
of these lines, except the key:
<<< list of "key" = "string"; >>>
I need the result in a single output, but prefix each language with a comment with its language code, e.g. for English:
// en
Remember that Chinese language code is zh-Hans.
Thanks!