我需要在与此类似的文件(~45k行)中翻译<DefaultValue>
标记:
<Resources>
<Resource>
<File>App_GlobalResources\Ecommerce_Modules.ascx.resx</File>
<Key>ModuleTitle.ecTermsAndConds</Key>
<DefaultValue>Terms And Conditions</DefaultValue>
<Value>1</Value>
</Resource>
<Resource>
<File>App_GlobalResources\Ecommerce_Modules.ascx.resx</File>
<Key>ModuleTitle.ecStorefrontCatalogMenu</Key>
<DefaultValue>Catalog Menu</DefaultValue>
<Value>1</Value>
</Resource>
...
</Resources>
我查看了Google Translator Toolkit,但它不支持任意XML。有一些付费服务,但目前谷歌翻译就足够了。
我可以使用xmlstarlet
提取所有标记/文字,但如何通过翻译更新值?
xmlstarlet sel -t -m "/Resources/Resource" -c "./DefaultValue" -n ~/Downloads/Resources.xml
答案 0 :(得分:1)
我使用curl
,own Bash script和google web translator
创建我的xmlstarlet
来解决此问题。
我正在循环包含要翻译的文本的每个元素,调用翻译函数(例如Google翻译),并使用翻译更新输出文件中的给定元素。 因此,您需要在脚本文件中为表达式定义XPath:
# @description Xpath to each item is build as $xpath[i]/$i18nTag
xpath="/Resources/Resource"
i18nTag="DefaultValue"
然后运行:
./xml-translator.bash en fr ./input.xml
检查./input.fr.xml
中的结果。