How to extract strings from plist files for translation (localization)?

本秂侑毒 提交于 2019-12-10 21:19:36

问题


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.

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.


回答1:


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

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)




回答2:


We recently made a small online application to do that, please take a look on: http://www.icapps.be/plist-translator/




回答3:


I can't think of any command off the top of my head. However, plists are glorified xml files and there are various parsers available for them.

It shouldn't be too difficult to create a simple python script to get all the strings from the file.




回答4:


Does this help? http://www.icanlocalize.com/site/tutorials/how-to-translate-plist-files/

We much prefer paying clients who use our translation system with our translators, but you can translate yourself in our GUI at no charge.



来源:https://stackoverflow.com/questions/6271715/how-to-extract-strings-from-plist-files-for-translation-localization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!