gpt4 book ai didi

xcode - 通过 xCode 构建阶段自动下载 POEditor 翻译

转载 作者:行者123 更新时间:2023-12-02 03:38:33 25 4
gpt4 key购买 nike

我正在使用 POEditor.com 来管理应用程序的翻译。他们有一个 REST API,应该允许我们每次在 xCode 中进行构建时自动获取翻译。我想分享我为此编写的 bash 脚本(回答我自己的问题:)

最佳答案

在您的主文件夹结构中创建一个 tools 文件夹,并将下面提供的“poeditorfetch”脚本复制到其中:

enter image description here

enter image description here将新的构建阶段“POEditor translations”添加到您的 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

关于xcode - 通过 xCode 构建阶段自动下载 POEditor 翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49380814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com