- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我想编写一个简单的解决方案来备份我们目前在 smarting 上拥有的所有字符串文件。这包括任何语言环境文件。
目前我还有许多其他问题,但主要目标是下载所有文件。
单个文件的当前 curl 是:
curl -d "apiKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx
&fileUri=%2Fpath%2Fto%2Ffolder%2Fstrings.xml
&projectId=1234567890" "https://api.smartling.com/v1/file/get/"
这将为我提供一个 strings.xml 文件。我可以使用 &locale=DE
进一步定义语言环境,以获得包含翻译的相同文件。
我可以使用通配符下载所有 *.xml 文件吗?
最佳答案
Smartling 有一个与 Smrtling API 交互的 shell 脚本,可以执行此类操作(以及更多)。假设您想下载所有已翻译的文件以及已发布的翻译,该命令类似于:
./download-smartling-files.sh -t published -a xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -p 1234567890 -l "nl-NL ru-RU"
请务必使用您为 Smartling 项目配置的语言环境更新 locales -l 参数。
如果您想下载所有文件,包括任何和所有待处理的翻译以及已发布的翻译,那么该命令将类似于
./download-smartling-files.sh -t pending -a xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx -p 1234567890 -l "nl-NL ru-RU"
这两个命令都将与 Smartling API 交互以获取当前上传到 Smartling 的所有文件的列表,然后遍历它们,将翻译后的文件下载到 translated/[locale] 目录
您可以通过脚本执行许多其他操作,包括下载所有翻译的 TMX 文件。要了解如何执行此操作以及其他操作,只需运行
./download-smartling-files.sh
另一种选择是使用 Smartling Maven Plugin 。这通常在将本地化整合到您的构建过程中并且您希望在构建和部署事件期间上传和/或下载文件时使用。
这里是 download-smartling-files.sh 脚本
#!/bin/bash
# author: Eric Negron (enegron@smartling.com)
# last updated February 20, 2014
shopt -s nullglob
function delete_files () {
# print the files first to make damn sure they know what they are deleting
COUNT=1
for CURRENT_FILE in ${uris[@]}
do
echo $'\n'$COUNT" "$CURRENT_FILE
((COUNT++))
done
echo "Are you SURE you want to delete all "${#uris[@]}" files?"
# confirm by getting the user to enter 'YES' to input, and if YES then delete these files
COUNT=1
read delete_confirmation
if [ $delete_confirmation != "YES" ]; then
echo "sorry, must answer YES to delete. exiting"
exit
else
for CURRENT_FILE in ${uris[@]}
do
echo $'\n'$COUNT" "$CURRENT_FILE
curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&fileUri=$CURRENT_FILE" "https://$SERVER_URL/v1/file/delete"
((COUNT++))
done
fi
}
function usage {
cat << EOF
This script uses the Smartling API
OPTIONS:
-h Show this message
-t (REQUIRED) download type. Acceptable types: original | published | p100 | pseudo | pending | TMX | DELETE
-a (REQUIRED) API key
-p (REQUIRED) project ID
-u (OPTIONAL) URI mask
-l (OPTIONAL) locales list - a qouted array of Smartling Locales. E.G. "es-ES ja-JP"
-x (OPTIONAL) TMX download type: full (default) | published - only valid with -t TMX
-d (OPTIONAL) when downloading translations or TMX set this option to false to append filename with locale instead of creating locale folders. Not valid with -t original option.
-E (OPTIONAL) DELETE files -E must be true and type = DELETE and must use -u MASK option
EOF
}
# hardcode to regular API, not sandbox
SERVER_URL=api.smartling.com
#opt t
DL_TYPE=
#opt a
SL_APIKEY=
#opt p
SL_PROJECT=
#opt u
URI_MASK=
#opt u
LOCALES=
#opt x
TMX_FLAG="full"
#opt d
USE_LOCALE_DIR="true"
#opt E
DELETE_CONFIRM="false"
while getopts "ht:a:p:u:l:x:d:E:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
t)
DL_TYPE=$OPTARG
;;
a)
SL_APIKEY=$OPTARG
;;
p)
SL_PROJECT=$OPTARG
;;
u)
URI_MASK=$OPTARG
;;
l)
LOCALES=($OPTARG)
;;
x)
TMX_FLAG=$OPTARG
;;
d)
USE_LOCALE_DIR=$OPTARG
;;
E)
DELETE_CONFIRM=$OPTARG
;;
esac
done
# make sure the required paramaters are set to something
# TODO check if getops handles this natively in some way
if [ "$DL_TYPE" == "" ] || [ "$SL_APIKEY" == "" ] || [ "$SL_PROJECT" == "" ]; then
usage
exit
fi
# make sure download type is valid
if [ "$DL_TYPE" != "original" ]\
&& [ "$DL_TYPE" != "published" ]\
&& [ "$DL_TYPE" != "p100" ]\
&& [ "$DL_TYPE" != "pseudo" ]\
&& [ "$DL_TYPE" != "pending" ]\
&& [ "$DL_TYPE" != "TMX" ]\
&& [ "$DL_TYPE" != "DELETE" ]; then
echo "INVALID TYPE. Acceptable types: original | published | p100 | pseudo | pending | TMX. Exiting."
exit
fi
# if user has specified mask confirm it - note mask means nothing to TMX
if [ "$URI_MASK" != "" ]; then
if [ $DL_TYPE == "TMX" ]; then
echo "Mask option has no effect when downloading TMX. Ignoring."
URI_MASK=""
else
echo "mask was set!"$'\n'
fi
fi
IFS=$'\n'
#make sure there are no API configuration errors by doing a file/list call just to check for error conditions
errors=($(curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&uriMask=$URI_MASK" "https://$SERVER_URL/v1/file/list" | grep -Eo "ERROR"))
error_count=${#errors[@]}$'\n'
if [ $error_count -gt 0 ]; then
echo "error with either the API key or Project ID - verify your values."
exit
fi
# figure out how many total files there - because if more than standard 500 returned in list, then need to paginate to build the list of uris
# need to move this check since if downloading TMX it's possible there are no files.
total_files=($(curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&uriMask=$URI_MASK" "https://$SERVER_URL/v1/file/list" | grep -Eo "fileCount\":[0-9]+" | sed -e 's/fileCount\"://g'))
# The /file/list API has a limit of 500 items, if the total needed is more, need to make multiple calls to build the full URI list
listLimit=500
# figure out how many passes in batches of 500 needed
let "passes=$total_files/$listLimit"
# if more than 1 batch needed, then make as many passes as needed to build the list
pass=0
while [ $pass -le $passes ]; do
let "passOffset=$pass*$listLimit"
uris+=($(curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&uriMask=$URI_MASK&offset=$passOffset" "https://$SERVER_URL/v1/file/list" | grep -Eo "fileUri\":\"[^\"]*" | sed -e 's/fileUri":"//g'))
((pass++))
done
# exit if requesting to download files, but nothing matched at all, otherwise show the count of files that matched and the names
# TODO: refactor since TMX handling is different with getopts
file_count=${#uris[@]}
if [ $file_count = "0" ] && [ $DL_TYPE != "TMX" ]; then echo "nothing to operate on, exiting!"; exit; fi
# if deleting check all the parameters set and if so pass of URI mask list to delete function
if [ "$DL_TYPE" == "DELETE" ]; then
if [ "$DELETE_CONFIRM" == "true" ] && [ "$URI_MASK" != "" ]; then
delete_files $uris
exit
else
echo "Must set -u to a uri mask value and must set -E true to confirm deletion. Exiting"
exit
fi
fi
# if not downloading TMX - then list the files we found
echo "total files to download "$total_files$'\n'
if [ $DL_TYPE != "TMX" ]; then echo "URIs: "${uris[@]}$'\n'; fi
#BEGIN ORIGINALS
if [ "$DL_TYPE" == "original" ] ; then
echo "downloading originals"
echo "files to download: "$file_count$'\n'
# create the originals folder if it doesn't exist
if [ ! -d "originals" ]; then
echo "making originals folder"$'\n'
mkdir originals
fi
COUNT=0
# go through the list of files to download (in each language)
for CURRENT_FILE in ${uris[@]}
do
echo $CURRENT_FILE
((COUNT++))
echo $COUNT
# since the URI includes full URI including default smartling prefix '/files/' or any other prefix specified - strip that and just use the last part after the last /
# e.g. if the URI is /files/filename.ext then BF_NAME will be filename.ext - this what we use for the local file name (in the folder)
BF_NAME=${CURRENT_FILE##*/}
# This is curl call that downloads the originals. Since no LOCALE is set that is the behavior of /file/get
# becuase we are flattening the URIs to basename it's possible filenames could be duplicated - so to avoid this check if the file already exist and if it does use count to append name to create unique
# TODO USE COUNT
if [ -e originals/$BF_NAME ]; then
BF_NAME=$COUNT.$BF_NAME
echo "Updated BF_NAME"
fi
curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&fileUri=$CURRENT_FILE" "https://$SERVER_URL/v1/file/get" > originals/$BF_NAME
echo "downloaded URI: "$CURRENT_FILE" to: originals/"$BF_NAME$'\n'
done
exit
fi
#end of originals
# if not getting originals - then getting translations OR TMX - so get locales and then use that to download all
# get the list of locales for this project. Similar to above grep but the locale key value then sed for just the value
# if user has not set the locales array in the call, then get the full list via API
# TODO - validate the locales are good - otherwise user will just get empty files
if [ "$LOCALES" = "" ]; then
LOCALES=($(curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT" "https://$SERVER_URL/v1/project/locale/list" | grep -Eo "locale\":\"[^\"]*" | sed -e 's/locale":"//g'))
fi
echo "locales: "${#LOCALES[@]}$'\n'
# count of the locales
echo ${LOCALES[@]}$'\n'
#script puts the translated' versions in 'translated folder' with sub-folders for locales
if [ ! -d "translated" ]; then
echo "making translated folder"$'\n'
mkdir translated
fi
if [ $USE_LOCALE_DIR == "true" ]; then
#if [ "$USE_LOCALE_DIR" == "true" ]; then
# make the subfolders in the translated folder if they don't exist
for CURRENT_LOCALE in ${LOCALES[@]}
do
if [ ! -d translated/$CURRENT_LOCALE ]; then
echo "making "$CURRENT_LOCALE" folder" $'\n'
mkdir translated/$CURRENT_LOCALE
fi
done
fi
#TODO need to refactor TMX / MASK / PUBLISHED / FULL
# Download TMX
# Downloading TMX uses a different API than downloading tranlated files
if [ "$DL_TYPE" == "TMX" ] ; then
echo "downloading TMX "$TMX_FLAG
for CURRENT_LOCALE in ${LOCALES[@]}
do
# if using folders - set the folder locale
# else using file-names so set the filename locale
if [ "$USE_LOCALE_DIR" == "true" ]; then
LOCALE_DIR=$CURRENT_LOCALE"/"
FILE_LOCALE="TMX-"
else
FILE_LOCALE=$CURRENT_LOCALE"-"
LOCALE_DIR=""
fi
curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&locale=$CURRENT_LOCALE&format=TMX&dataSet=$TMX_FLAG" "https://$SERVER_URL/v1/translations/download" > translated/$LOCALE_DIR$FILE_LOCALE"TMX.xml"
echo "downloaded " $CURRENT_LOCALE "TMX" $'\n'
done
exit
fi
# downloading translations of files
# by this point the file list has already been filtered and the and the locale list has been created
# go through the list of files to download (in each language)
COUNT=0
P100=0
# since I use DL_TYPE as actual parameter to API call need to set this back to actual "published" before entering loop to download
if [ $DL_TYPE == "p100" ]; then
DL_TYPE="published"
P100=1
fi
for CURRENT_FILE in ${uris[@]}
do
echo $CURRENT_FILE
((COUNT++))
echo $COUNT
# loop through all the locales for each file
for CURRENT_LOCALE in ${LOCALES[@]}
do
# if using folders - set the folder locale
# else using file-names so set the filename locale
if [ $USE_LOCALE_DIR == "true" ]; then
LOCALE_DIR=$CURRENT_LOCALE"/"
FILE_LOCALE=""
else
FILE_LOCALE=$CURRENT_LOCALE"-"
LOCALE_DIR=""
fi
# since the URI includes full URI including default smartling prefix '/files/' or any other prefix specified - strip that and just use the last part after the last /
# e.g. if the URI is /files/filename.ext then BF_NAME will be filename.ext - this what we use for the local file name (in the locale folder)
BF_NAME=${CURRENT_FILE##*/}
EXT=${BF_NAME##*.}
# rename .pot files to .po - we really should be checking the header from the /file/get API call but this is just simpler
if [ "$EXT" == "pot" ]; then
filename=${BF_NAME%.*}
BF_NAME=$filename".po"
echo "renamed pot to po"
fi
# because we are flattening the URIs to basename it's possible filenames could be duplicated - so to avoid this check if the file already exist and if it does use COUNT to append name to create unique
if [ -e translated/$LOCALE_DIR$FILE_LOCALE$BF_NAME ]; then
BF_NAME=$COUNT.$BF_NAME
echo "Updated BF_NAME"
fi
# Here if user is doing 100% published need to test and if it's not then skip it
# probably should do this earlier in this loops to avoid other tests but thare not needed if we are just going to skip the file
if [ $P100 == 1 ]; then
# echo "requested 100 percent only"
# use api status call and pull out the part of the response that has the string count and completed string count
completeStatus=($(curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&fileUri=$CURRENT_FILE&locale=$CURRENT_LOCALE" "https://$SERVER_URL/v1/file/status" | grep -Eo "stringCount\":[0-9]+.*\"completedStringCount\":[0-9]+" ))
# strip those out as separate variables to test
stringCount=($(echo $completeStatus | sed -E 's/stringCount\":([0-9]+).*/\1/g'))
completedStringCount=($(echo $completeStatus | sed -E 's/.*completedStringCount\":([0-9]+).*/\1/g'))
#echo $stringCount","$completedStringCount
# set download to 1 only if 100%
if [ $stringCount == $completedStringCount ]; then
download=1
echo $CURRENT_FILE" in "$CURRENT_LOCALE" is 100% complete!"$'\n'
else
download=0
echo "100% complete requested. Skipping URI: "$CURRENT_FILE" in "$CURRENT_LOCALE" total:"$stringCount", completed:"$completedStringCount$'\n'
fi
else
# didn't ask for 100% so always download
download=1
fi
if [ $download == 1 ]; then
# This is the actual curl command that downloads the given file for given locale, and state as specified when called
curl -sS -d "apiKey=$SL_APIKEY&projectId=$SL_PROJECT&fileUri=$CURRENT_FILE&locale=$CURRENT_LOCALE&retrievalType=$DL_TYPE" "https://$SERVER_URL/v1/file/get" > translated/$LOCALE_DIR$FILE_LOCALE$BF_NAME
echo "downloaded URI: "$CURRENT_FILE" to: translated/"$LOCALE_DIR$FILE_LOCALE$BF_NAME$'\n'
fi
done
done
exit
关于xml - curl 从 Smartling 下载所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25681725/
今天我在一个 Java 应用程序中看到了几种不同的加载文件的方法。 文件:/ 文件:// 文件:/// 这三个 URL 开头有什么区别?使用它们的首选方式是什么? 非常感谢 斯特凡 最佳答案 file
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个 javascript 文件,并且在该方法中有一个“测试”方法,我喜欢调用 C# 函数。 c# 函数与 javascript 文件不在同一文件中。 它位于 .cs 文件中。那么我该如何管理 j
需要检查我使用的文件/目录的权限 //filePath = path of file/directory access denied by user ( in windows ) File fil
我在一个目录中有很多 java 文件,我想在我的 Intellij 项目中使用它。但是我不想每次开始一个新项目时都将 java 文件复制到我的项目中。 我知道我可以在 Visual Studio 和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有 3 个组件的 Twig 文件: 文件 1: {# content-here #} 文件 2: {{ title-here }} {# content-here #}
我得到了 mod_ldap.c 和 mod_authnz_ldap.c 文件。我需要使用 Linux 命令的 mod_ldap.so 和 mod_authnz_ldap.so 文件。 最佳答案 从 c
我想使用PIE在我的项目中使用 IE7。 但是我不明白的是,我只能在网络服务器上使用 .htc 文件吗? 我可以在没有网络服务器的情况下通过浏览器加载的本地页面中使用它吗? 我在 PIE 的文档中看到
我在 CI 管道中考虑这一点,我应该首先构建和测试我的应用程序,结果应该是一个 docker 镜像。 我想知道使用构建环境在构建服务器上构建然后运行测试是否更常见。也许为此使用构建脚本。最后只需将 j
using namespace std; struct WebSites { string siteName; int rank; string getSiteName() {
我是 Linux 新手,目前正在尝试使用 ginkgo USB-CAN 接口(interface) 的 API 编程功能。为了使用 C++ 对 API 进行编程,他们提供了库文件,其中包含三个带有 .
我刚学C语言,在实现一个程序时遇到了问题将 test.txt 文件作为程序的输入。 test.txt 文件的内容是: 1 30 30 40 50 60 2 40 30 50 60 60 3 30 20
如何连接两个tcpdump文件,使一个流量在文件中出现一个接一个?具体来说,我想“乘以”一个 tcpdump 文件,这样所有的 session 将一个接一个地按顺序重复几次。 最佳答案 mergeca
我有一个名为 input.MP4 的文件,它已损坏。它来自闭路电视摄像机。我什么都试过了,ffmpeg , VLC 转换,没有运气。但是,我使用了 mediainfo和 exiftool并提取以下信息
我想做什么? 我想提取 ISO 文件并编辑其中的文件,然后将其重新打包回 ISO 文件。 (正如你已经读过的) 我为什么要这样做? 我想开始修改 PSP ISO,为此我必须使用游戏资源、 Assets
给定一个 gzip 文件 Z,如果我将其解压缩为 Z',有什么办法可以重新压缩它以恢复完全相同的 gzip 文件 Z?在粗略阅读了 DEFLATE 格式后,我猜不会,因为任何给定的文件都可能在 DEF
我必须从数据库向我的邮件 ID 发送一封带有附件的邮件。 EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Adventure Works Admin
我有一个大的 M4B 文件和一个 CUE 文件。我想将其拆分为多个 M4B 文件,或将其拆分为多个 MP3 文件(以前首选)。 我想在命令行中执行此操作(OS X,但如果需要可以使用 Linux),而
快速提问。我有一个没有实现文件的类的项目。 然后在 AppDelegate 我有: #import "AppDelegate.h" #import "SomeClass.h" @interface A
我是一名优秀的程序员,十分优秀!