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

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

But I also have many texts to translate into plist files (String field types enclosed in a string tag ). Is there a good bash script / command to extract these lines into a flat txt file? I could view and filter it so that my translators can work with a good list, but not with an alien XML file.

+3
source share
4 answers

I created a custom shell script that tries to figure out the right values. Then you can use localize.py script in a modified way (see below) to automatically create translation files. (Line break, somewhere very important). If there are more objects to translate, 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 script requires some modification. Therefore, I created a small package containing a localizer for the source code and for the plist files. The new script supports Duplikates (which means it will hit them)

+2
source

- . , plists - xml , .

python script, .

0

Source: https://habr.com/ru/post/1710691/


All Articles