So the solution was to make a copies of the files for each language and install them to $DATADIR/step/$LANG/examples. Despite being simple, this solution has serious problems:
- as there are no .pot files, translators simply don't know that the files are translatable
- translators should deal with strange unfamiliar format, they can't use convenient tools like Lokalize
- keeping translations in sync is really hard
- Extract strings from XML file to .po file (in Messages.sh script)
- The .po files will be handled by translators as usual
- Merge strings back to XML files when building l10n module
Instead of implementing something just for Step, I have written a more generic solution: extractxml. This is a rather simple python script that can be used to translate a variety of XML-based formats. The usage is simple, for example a command:
$ extractxml --context='%(tag)s' --tag=name --tag=text \will extract the content of "name" and "text"
--extract test*.xml --xgettext --output=test.po
$ extractxml --context='%(tag)s' --tag=name --tag=text \will merge the translated strings back and save the translated files into i18n subdirectory.
--translate --po-file=test.po test*.xml --output-dir=i18n
The extractxml has some more features, just run "extractxml --help" to see them all. For example it is capable to match tags by regular expressions, strip and unquote the strings, recursively handle embedded XML fragments (for example rich text generated by Qt Designer).
Currently extractxml lives in trunk/kdeedu/step/step/data, but in case there will be some interest in it, I will be happy to move it to a more prominent location.