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

如何在使用Xcode String Catalogs时兼容Phrase.com翻译服务?

获取Xcode String Catalog编译生成的.strings/.stringsdict文件方法

方法一:通过xcodebuild命令指定输出目录

直接用命令行编译项目,指定衍生数据输出路径,方便定位生成的本地化文件:

xcodebuild -project YourProject.xcodeproj -scheme YourScheme -configuration Release -derivedDataPath ./BuildOutput

编译完成后,在以下路径找到目标文件:
./BuildOutput/Build/Products/Release-<你的平台>/<你的App名称>.app/Contents/Resources/<语言代码>.lproj/
比如zh-Hans.lproj、en.lproj文件夹内,就是编译生成的.strings和.stringsdict文件。

方法二:添加编译脚本自动导出文件

在Xcode中给目标添加一个Run Script Phase,实现编译完成后自动将生成的本地化文件复制到指定目录,省去手动查找的麻烦:

  1. 打开Xcode项目,选中目标 -> 切换到Build Phases标签
  2. 点击**+** -> 选择New Run Script Phase,将其拖到Compile Sources之后
  3. 替换脚本内容为:
# 定义导出目录(可自行修改)
EXPORT_DIR="${SRCROOT}/ExportedStrings"
mkdir -p "$EXPORT_DIR"

# 定位App包内的资源目录
APP_RESOURCES_DIR="${BUILT_PRODUCTS_DIR}/${TARGET_NAME}.app/Contents/Resources"

# 遍历所有本地化目录,复制strings文件
for LPROJ in "$APP_RESOURCES_DIR"/*.lproj; do
    if [ -d "$LPROJ" ]; then
        LANG=$(basename "$LPROJ" .lproj)
        DEST_DIR="$EXPORT_DIR/${LANG}.lproj"
        mkdir -p "$DEST_DIR"
        cp "$LPROJ"/*.strings "$DEST_DIR/" 2>/dev/null
        cp "$LPROJ"/*.stringsdict "$DEST_DIR/" 2>/dev/null
    fi
done

编译项目后,生成的.strings和.stringsdict文件会自动保存到项目根目录的ExportedStrings文件夹中。

后续处理

将导出的文件上传至Phrase.com完成翻译后,下载翻译好的.strings/.stringsdict文件,直接拖入Xcode项目中,Xcode会自动将其转换为String Catalog格式适配项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 07:00:05