我正在使用POEditor.com来管理应用程序的翻译。他们有一个REST API,每次我们在xCode中进行构建时都应该允许自动获取翻译。我想分享我写的bash脚本来做这件事(回答我自己的问题:)
答案 0 :(得分:1)
在主文件夹结构中创建一个工具文件夹,并复制下面提供的" poeditorfetch"其中的脚本:
添加新的构建阶段" POEditor翻译"到您的xCode配置:
这是脚本:
#!/bin/bash
#update these values with the values for your project => go to the POEditor website / API integration
POEDITOR_API_TOKEN="a1b2c3d4e5f6g7h8i9j10klmnopqrstuvw"
POEDITOR_PROJECT_ID="123456"
#because the language code for POEditor can differ from the code used by xCode we must specify the poeditorcode->xCodecode
#this is also handy to download eg. xCode's Base language from English for example!
POEDITOR_LANGUAGES_VS_XCODE_FOLDERS=("en->Base" "en->en" "fr-be->fr" "nl->nl")
ROOT_LOCALIZATION_FOLDER="./resource/translations/"
#extractUrlFromPOEditorJson function which extracts the url from $json global variable
function extractUrlFromPOEditorJson {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w item`
echo ${temp##*|}
}
#downloads the strings file for one language, uses currentLanguageCodePOEditor, currentLangaugeCodeXCode as input variables and the POEDITOR_xxx and ROOT_LOCALIZATION_FOLDER as constants
function downloadOneLanguage {
outputfile=$ROOT_LOCALIZATION_FOLDER$currentLangaugeCodeXCode".lproj/Localizable.strings"
#first fetech the download url from po editor
echo "*************** $currentLanguageCodePOEditor -> $outputfile ***************"
echo Fetching POEditor URL...
json=`curl -s -# -X POST https://poeditor.com/api/ \
-d api_token="$POEDITOR_API_TOKEN" \
-d action="export" \
-d id="$POEDITOR_PROJECT_ID" \
-d language="$currentLanguageCodePOEditor" \
-d type="apple_strings"`
#echo $json
url=`extractUrlFromPOEditorJson`
#echo $url
#fetch the actual strings file
echo Downloading translation file...
curl -# -s -X GET $url -o $outputfile
}
for value in "${POEDITOR_LANGUAGES_VS_XCODE_FOLDERS[@]}"; do
currentLanguageCodePOEditor="${value%%->*}"
currentLangaugeCodeXCode="${value##*->}"
downloadOneLanguage
done