You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Xcode构建阶段自动获取POEditor翻译的Bash脚本分享

Automatically Fetch POEditor Translations on Xcode Build

I’ve been using POEditor to manage translations for my iOS apps for a while now, and one thing that bugged me was having to manually download the latest strings every time I wanted to test updated translations. So I built a Bash script that hooks into POEditor’s REST API to automatically pull fresh translations on every Xcode build. Here’s how it works:

The Script

This script handles authenticating with POEditor, fetching your project's active languages, downloading translations in Apple's .strings format, and placing them directly into your Xcode project's localization directories.

#!/bin/bash

# Configuration - Update these with your POEditor details
POEDITOR_API_TOKEN="your_api_token_here"
POEDITOR_PROJECT_ID="your_project_id_here"
# Path to your app's localization folder (adjust this to match your project structure)
LOCALIZATION_DIR="./YourApp/Resources/Localizations"

# Create the localization directory if it doesn't exist
mkdir -p "$LOCALIZATION_DIR"

# Check if jq is installed (required to parse JSON responses from POEditor)
if ! command -v jq &> /dev/null; then
    echo "Error: jq is missing! Install it first with 'brew install jq' (macOS) or your system's package manager."
    exit 1
fi

# Fetch the list of active languages in your POEditor project
LANGUAGES=$(curl -s -X POST "https://api.poeditor.com/v2/languages/list" \
  -d "api_token=$POEDITOR_API_TOKEN" \
  -d "id=$POEDITOR_PROJECT_ID" | jq -r '.result.languages[].code')

# Download and organize translations for each language
for LANG in $LANGUAGES; do
    echo "Fetching translations for language: $LANG"
    
    # Download the .strings file from POEditor
    curl -s -X POST "https://api.poeditor.com/v2/projects/export" \
      -d "api_token=$POEDITOR_API_TOKEN" \
      -d "id=$POEDITOR_PROJECT_ID" \
      -d "language=$LANG" \
      -d "type=apple_strings" > "$LOCALIZATION_DIR/temp_$LANG.strings"
    
    # Create the language-specific .lproj directory (Xcode's expected structure)
    LANG_PROJ_DIR="$LOCALIZATION_DIR/$LANG.lproj"
    mkdir -p "$LANG_PROJ_DIR"
    
    # Move the downloaded file to the correct location and rename to Localizable.strings
    mv "$LOCALIZATION_DIR/temp_$LANG.strings" "$LANG_PROJ_DIR/Localizable.strings"
done

echo "✅ All translations successfully pulled from POEditor and ready for build!"

Setup Steps

  1. Add your POEditor credentials: Replace your_api_token_here and your_project_id_here with the values from your POEditor account (you can find these in your account's API settings).
  2. Set the correct path: Update LOCALIZATION_DIR to point to where your Xcode project stores its localization files (usually something like ${SRCROOT}/YourAppName/Localizations).
  3. Install jq: This script uses jq to parse JSON responses from POEditor. On macOS, install it with brew install jq; on Linux, use your distribution's package manager (e.g., sudo apt install jq).
  4. Add to Xcode as a Run Script Phase:
    • Open your Xcode project, select your app target, and go to the Build Phases tab.
    • Click the + button at the top and select New Run Script Phase.
    • Paste the path to your script (e.g., ${SRCROOT}/Scripts/fetch_poeditor_translations.sh) into the script field.
    • Drag this new run script phase before the "Copy Bundle Resources" phase so the fresh translations are included in your build.

Now every time you build your app in Xcode, it will automatically pull the latest translations from POEditor—no more manual downloads!

内容的提问来源于stack exchange,提问作者HixField

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:58:50