Export Localizations #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Export Localizations | |
| on: | |
| push: | |
| branches: [develop] | |
| paths: | |
| - 'Supporting Files/Localizable.xcstrings' | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| export-xliff: | |
| runs-on: macos-latest | |
| if: ${{ github.actor != 'github-actions' && !contains(github.event.head_commit.message, '[localization-bot]') }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Select Xcode 16.4 | |
| run: sudo xcode-select --switch /Applications/Xcode_16.4.app | |
| - name: Export XLIFF | |
| run: | | |
| set -euo pipefail | |
| rm -rf LocalizationExport | |
| mkdir -p LocalizationExport | |
| xcodebuild \ | |
| -project OPass.xcodeproj \ | |
| -scheme OPass \ | |
| -localizationPath LocalizationExport \ | |
| -exportLocalizations \ | |
| -exportLanguage en \ | |
| -exportLanguage ja \ | |
| -exportLanguage nan \ | |
| -exportLanguage zh-Hant | |
| rm -f *.xliff || true | |
| find LocalizationExport -name "*.xliff" -print0 | xargs -0 -I{} cp "{}" . || true | |
| - name: Commit XLIFF | |
| run: | | |
| ls | |
| set -euo pipefail | |
| shopt -s nullglob | |
| files=( *.xliff ) | |
| if [ ${#files[@]} -eq 0 ]; then | |
| echo "No XLIFF export found. Skipping commit." | |
| exit 0 | |
| fi | |
| for file in "${files[@]}"; do | |
| perl -i -0777 -pe 's/<file original=".*<file original="Supporting Files\/Localizable\.xcstrings"/<file original="Supporting Files\/Localizable.xcstrings"/sg' "$file" | |
| done | |
| tmp=".xliff_tmp" | |
| rm -rf "$tmp" | |
| mkdir -p "$tmp" | |
| mv "${files[@]}" "$tmp/" | |
| if git ls-remote --exit-code --heads origin xliff > /dev/null 2>&1; then | |
| git fetch origin xliff:refs/remotes/origin/xliff || true | |
| git switch -c xliff --track origin/xliff 2>/dev/null || git switch xliff | |
| else | |
| git switch --orphan xliff | |
| fi | |
| shopt -s nullglob | |
| mv "$tmp"/*.xliff . || true | |
| rmdir "$tmp" || true | |
| xliffs=( *.xliff ) | |
| if [ ${#xliffs[@]} -eq 0 ]; then | |
| echo "No XLIFFs after branch switch. Nothing to commit." | |
| exit 0 | |
| fi | |
| git add "${xliffs[@]}" | |
| if ! git diff --cached --quiet; then | |
| git -c user.name="github-actions" -c user.email="actions@users.noreply.github.com" \ | |
| commit -m "[localization-bot] Export Apple XLIFF from String Catalogs" | |
| git push -u origin xliff | |
| else | |
| echo "No XLIFF changes." | |
| fi |