如何从plist文件中提取字符串以进行翻译(本地化)? [英] How to extract strings from plist files for translation (localization)?

查看:253
本文介绍了如何从plist文件中提取字符串以进行翻译(本地化)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要准备用于翻译iPhone应用程序的字符串列表. 我使用genstring 从 *.m文件中提取了字符串,并使用ibtool 命令从XIB文件中提取了.

I need to prepare list of strings for translation of my iPhone application. I have extracted strings from *.m files using genstring and from the XIB files using ibtool command.

但是我还有大量文本要翻译成plist文件(字符串标签中包含的字符串字段类型). 是否有一个不错的bash脚本/命令将这些字符串提取到平面txt文件中? 我可以对其进行审核和过滤,以使我的翻译人员可以使用不错的列表,但不能使用看起来像外星人的XML文件.

But I have also lots of texts to translate in plist files (String field types enclosed in string tag). Is there a nice bash script / command to extract those strings into a flat txt file? I could review and filter it so my translators can work with nice list but not with alien looking XML file.

推荐答案

我制作了一个自定义的shell脚本,该脚本试图找出所需的值.然后,您可以使用 localize.py 脚本的一种经过修改的方式(请参见下文),以自动创建翻译文件. (换行符在某种程度上非常重要)如果要翻译的实体更多,则可以相应地修改shell脚本

I made a custom shell script which tries to figure out the values needed. You can then use the localize.py script in a modified way (see below) to automatically create the translation files. (The line break where somehow very important) If there more entities to be translated, the shell script can be modified accordingly

#!/bin/bash

rm -f $2

sed -n 'N;/<key>Title<\/key>/{N;/<string>.*<\/string>/{s/.*<string>\(.*\)<\/string>.*/\/*     \1 *\/\
"\1" = "\1";\
/p;};}' $1 >> $2

sed -n 'N;/<key>FooterText<\/key>/{N;/<string>.*<\/string>/{s/.*<string>\(.*\)<\/string>.*/\/* \1 *\/\
\"\1" = "\1";\
/p;}
;}' $1 >> $2

sed -n 'N;/<key>Titles<\/key>/{N;/<array>/{:a
N;/<\/array>/!{
/<string>.*<\/string>/{s/.*<string>\(.*\)<\/string>.*/\/* \1 *\/\
\"\1" = "\1";\
/p;}
ba
;};};}' $1 >> $2

localize.py脚本需要进行一些修改.因此,我创建了一个小包,其中包含用于源代码和plist文件的本地化程序.新脚本甚至支持Duplikates(意味着它将踢他们)

the localize.py script needed some modification. Therefore I created a small package containing the localizer for the source code and for the plist Files. The new script even supports Duplikates (meaning it will kick them)

这篇关于如何从plist文件中提取字符串以进行翻译(本地化)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆