Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import manual translations with GPT #1037

Merged
merged 5 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fastlane/**/trade_representative_contact_information
build/
dist/
/iap/
/l10n/
screenshots/html/*/0*.png
screenshots/results/
/templates/
Expand Down
2 changes: 2 additions & 0 deletions scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
55 changes: 55 additions & 0 deletions scripts/import-translations.sh
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/import-translations.txt
Original file line number Diff line number Diff line change
@@ -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!