diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2025-09-03 12:50:39 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2025-09-03 12:50:39 +0200 |
| commit | 034d5d24dc233fb8013f94d7a9661141af9539a7 (patch) | |
| tree | 92d9916058f191da560881a115f02a36d03ebeee | |
| parent | 61ce57ec6dc117bdea664a9769d2746372ccef2d (diff) | |
| parent | 32a2024a1d3c4a593e9f134f38babc881b49e7cb (diff) | |
| download | mullvadvpn-034d5d24dc233fb8013f94d7a9661141af9539a7.tar.xz mullvadvpn-034d5d24dc233fb8013f94d7a9661141af9539a7.zip | |
Merge branch 'add-ios-to-localization-script-ios-1222'
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 2 | ||||
| -rw-r--r-- | ios/translation/scripts/Readme.md | 4 | ||||
| -rwxr-xr-x | ios/translation/scripts/localizations.sh | 102 | ||||
| -rwxr-xr-x | scripts/localization | 27 |
4 files changed, 82 insertions, 53 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 657c7de6fd..0a5c250eac 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -5835,7 +5835,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint lint --quiet\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; 580E3F222A9861990061809D /* Run SwiftLint */ = { isa = PBXShellScriptBuildPhase; diff --git a/ios/translation/scripts/Readme.md b/ios/translation/scripts/Readme.md index 44674d7eff..a01bcbe5b1 100644 --- a/ios/translation/scripts/Readme.md +++ b/ios/translation/scripts/Readme.md @@ -26,8 +26,6 @@ This folder contains a Bash workflow that: ``` -> **Important:** Ensure `build/` and `logs/` are ignored by Git (see [Git Ignore](#git-ignore)). - --- ## Quick Start @@ -93,5 +91,3 @@ logs/ build_20250724_094401.log ``` -To prune logs older than 7 days automatically, the script includes an optional cleanup step (disabled by default; enable by setting `PRUNE_LOGS_DAYS`). - diff --git a/ios/translation/scripts/localizations.sh b/ios/translation/scripts/localizations.sh index 2129e3aa5a..629d501b4e 100755 --- a/ios/translation/scripts/localizations.sh +++ b/ios/translation/scripts/localizations.sh @@ -1,16 +1,14 @@ #!/usr/bin/env bash # localizations.sh -# Exports Swift/SwiftUI localization files (.xliff) from an Xcode project. +# Exports strings from and Imports them to an Xcode project. -#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LOG_DIR="$SCRIPT_DIR/logs" mkdir -p "$LOG_DIR" -LOG_FILE="$LOG_DIR/export-localization_$(date +%Y%m%d_%H%M%S).log" -TMP_LOG="$(mktemp)" +TMP_LOG="$(mktemp)" PROJECT_NAME="MullvadVPN" SCHEME_NAME="$PROJECT_NAME" XCODE_PROJECT_PATH="$SCRIPT_DIR/../../$PROJECT_NAME.xcodeproj" @@ -27,54 +25,63 @@ trap 'on_fail' ERR on_fail() { set +e - echo "โ Export failed. Cleaning up and saving log..." + echo "Export failed. Cleaning up and saving log..." cleanup_build_folder cleanup_temp_folder mkdir -p "$(dirname "$LOG_FILE")" cat "$TMP_LOG" >"$LOG_FILE" - echo "๐ฅ Full log saved to: $LOG_FILE" + echo "Full log saved to: $LOG_FILE" exit 1 } cleanup_build_folder() { - echo "๐งน Cleaning build folder at: $BUILD_OUTPUT_DIR" rm -rf "$BUILD_OUTPUT_DIR" } cleanup_temp_folder() { - echo "๐งน Cleaning temp folder at: $TMP_EXPORT_DIR" rm -rf "$TMP_EXPORT_DIR" } exec > >(tee "$TMP_LOG") 2>&1 build_project() { - echo "๐ Building project..." - xcodebuild \ + echo "Building project..." + if ! xcodebuild \ -project "$XCODE_PROJECT_PATH" \ -scheme "$SCHEME_NAME" \ -destination 'generic/platform=iOS' \ -configuration "$CONFIGURATION" \ -derivedDataPath "$DERIVED_DATA_DIR" \ + -quiet \ CODE_SIGNING_REQUIRED=NO \ CODE_SIGNING_ALLOWED=NO \ - clean build - echo "โ
Build succeeded" + clean build >"$TMP_LOG" 2>&1; then + echo "Failed to build project" + on_fail + fi + echo "Build succeeded" } export_localizations() { - echo "๐ Exporting localizations for languages: $EXPORT_LANGUAGES" + echo "Exporting localizations for languages: $EXPORT_LANGUAGES" IFS=',' read -r -a LANG_ARRAY <<<"$EXPORT_LANGUAGES" for lang in "${LANG_ARRAY[@]}"; do - echo "โก๏ธ Exporting $lang" - xcodebuild -exportLocalizations \ + # Run xcodebuild and capture errors + if ! xcodebuild -exportLocalizations \ -project "$XCODE_PROJECT_PATH" \ -scheme "$SCHEME_NAME" \ -derivedDataPath "$DERIVED_DATA_DIR" \ -localizationPath "$TMP_EXPORT_DIR" \ - -exportLanguage "$lang" + -exportLanguage "$lang" \ + -quiet \ + CODE_SIGNING_REQUIRED=NO \ + CODE_SIGNING_ALLOWED=NO \ + >"$TMP_LOG" 2>&1; then + echo "Failed to export localization for $lang" + on_fail + fi local xcloc_dir="${TMP_EXPORT_DIR}/${lang}.xcloc" @@ -83,13 +90,13 @@ export_localizations() { xliff_file=$(find "$xcloc_dir" -name '*.xliff' | head -n 1) if [[ -f "$xliff_file" ]]; then cp "$xliff_file" "$LOCALIZATION_DIR/${lang}.xliff" - echo "โ๏ธ Extracted $lang.xliff for Crowdin upload" + echo "Extracted $lang.xliff for Crowdin upload" else - echo "โ No .xliff file found in $xcloc_dir" + echo "No .xliff file found in $xcloc_dir" false fi else - echo "โ .xcloc bundle not found for $lang" + echo ".xcloc bundle not found for $lang" false fi done @@ -98,7 +105,7 @@ export_localizations() { clean_xliff_translations() { xliff_dir="$LOCALIZATION_DIR" if [[ ! -d "$xliff_dir" ]]; then - echo "โ Directory not found: $xliff_dir" + echo "Directory not found: $xliff_dir" return 1 fi @@ -108,16 +115,13 @@ clean_xliff_translations() { ["CFBundleDisplayName"]=1 # Add more keys here if needed ) - - echo "๐งน Cleaning unneeded keys from XLIFFs in $xliff_dir" for xliff in "$xliff_dir"/*.xliff; do if [[ -f "$xliff" ]]; then for key in "${!UNNEEDED_KEYS[@]}"; do sed -i '' -E "/<trans-unit[^>]*id=\"$key\"[^>]*>/,/<\/trans-unit>/d" "$xliff" done - echo "โ๏ธ Cleaned $xliff" else - echo "โ ๏ธ File not found: $xliff, skipping" + echo "File not found: $xliff, skipping" fi done @@ -137,61 +141,63 @@ import_localizations() { # Extract language code from filename, e.g., fr.xliff โ fr language_code=$(basename "$xliff_file" .xliff) - echo "๐ฅ Importing localization: $language_code from $xliff_file" + echo "Importing localization: $language_code from $xliff_file" + # Run xcodebuild and check for errors if ! xcodebuild -importLocalizations \ -project "$XCODE_PROJECT_PATH" \ -scheme "$SCHEME_NAME" \ -derivedDataPath "$DERIVED_DATA_DIR" \ -localizationPath "$xliff_file" \ -exportLanguage "$language_code" \ - -disableAutomaticPackageResolution; then - echo "โ Failed to import $xliff_file" - exit 1 + -quiet \ + CODE_SIGNING_REQUIRED=NO \ + CODE_SIGNING_ALLOWED=NO \ + >"$TMP_LOG" 2>&1; then + echo "Failed to import $xliff_file" + on_fail fi done - echo "โ
All localizations imported successfully." + echo "All localizations imported successfully." } localization_to_export() { - echo "๐ Export script started at: $(date)" + LOG_FILE="$LOG_DIR/export-localization_$(date +%Y%m%d_%H%M%S).log" build_project export_localizations clean_xliff_translations cleanup_build_folder cleanup_temp_folder - echo "๐ Export complete. Crowdin-ready .xliff files are in: $LOCALIZATION_DIR" - echo "โ
Script finished at: $(date)" + echo "Export complete. Crowdin-ready .xliff files are in: $LOCALIZATION_DIR" rm -f "$TMP_LOG" } localization_to_import() { - echo "๐ Import script started at: $(date)" + LOG_FILE="$LOG_DIR/import-localization_$(date +%Y%m%d_%H%M%S).log" build_project import_localizations cleanup_build_folder cleanup_temp_folder - echo "๐ Import complete. Localized .xliff files have been imported to code" - echo "โ
Script finished at: $(date)" + echo "Import complete. Localized .xliff files have been imported to code" rm -f "$TMP_LOG" } # Main entrypoint main() { case "${1:-}" in - export) - localization_to_export - ;; - import) - localization_to_import - ;; - "") - echo "Available subcommands: export, import" - ;; - *) - echo "โ Unknown parameter: $1" - exit 1 - ;; + export) + localization_to_export + ;; + import) + localization_to_import + ;; + "") + echo "Available subcommands: export, import" + ;; + *) + echo "Unknown parameter: $1" + exit 1 + ;; esac } diff --git a/scripts/localization b/scripts/localization index 084f61661c..ac0bf99240 100755 --- a/scripts/localization +++ b/scripts/localization @@ -62,6 +62,9 @@ function prepare_localization_strings { update_relay_locations_pot commit_changes "Update relay-locations.pot" + + update_ios_strings export + commit_changes "Update en.xliff" } function ensure_crowdin_api_key { @@ -77,6 +80,11 @@ function upload_to_crowdin { crowdin upload sources crowdin upload translations popd + + pushd ../ios/translation + crowdin upload sources + crowdin upload translations + popd } function download_from_crowdin { @@ -87,9 +95,17 @@ function download_from_crowdin { crowdin download popd + pushd ../ios/translation + crowdin download + popd + # Add new translations to Android xml-files log_header "Updating Android xml-files with new translations" sync_localizations + + # Add new translations to iOS source code + update_ios_strings import + commit_changes "Update translations" } @@ -110,6 +126,17 @@ function verify { exit 1 fi } +function update_ios_strings { + if [ $# -ne 1 ] || { [ "$1" != "export" ] && [ "$1" != "import" ]; }; then + echo "Usage: update_ios_strings [export|import]" >&2 + return 2 + fi + if [ "$1" = "export" ]; then + log_header "Extracting strings from iOS app source code" + else + log_header "Updating strings into iOS app source code with new translations" + fi +} main "$@" |
