From a187fd56e06dcf3bdec9acec1e1ea8dfeb579f30 Mon Sep 17 00:00:00 2001 From: Davide Date: Sun, 22 Dec 2024 10:10:54 +0100 Subject: [PATCH] Import manual translations with GPT (#1037) Save prompt for proper input format. --- .gitignore | 1 + scripts/env.sh | 2 ++ scripts/import-translations.sh | 55 +++++++++++++++++++++++++++++++++ scripts/import-translations.txt | 26 ++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100755 scripts/import-translations.sh create mode 100644 scripts/import-translations.txt diff --git a/.gitignore b/.gitignore index 05bd968c..5a0dc59a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ fastlane/**/trade_representative_contact_information build/ dist/ /iap/ +/l10n/ screenshots/html/*/0*.png screenshots/results/ /templates/ diff --git a/scripts/env.sh b/scripts/env.sh index 68dc43ed..0f54922a 100644 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -8,3 +8,5 @@ api_git="https://github.com/passepartoutvpn/api" api_version="v5" api_path=".api" api_package_path="Library/Sources/CommonAPI/API" +translations_input_path="l10n" +translations_output_path="Library/Sources/UILibrary/Resources" diff --git a/scripts/import-translations.sh b/scripts/import-translations.sh new file mode 100755 index 00000000..143b674a --- /dev/null +++ b/scripts/import-translations.sh @@ -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 diff --git a/scripts/import-translations.txt b/scripts/import-translations.txt new file mode 100644 index 00000000..0c83fce2 --- /dev/null +++ b/scripts/import-translations.txt @@ -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!