0
votes

I am making a quiz app which reads data from text files. The app works fine but I now want to translate it into English (from my native language). I can do that for strings defined in source files (.py) such as text on buttons etc., but have troubles with extracting text that needs translating from those text documents where all my questions and possible answers are.

I am using module gettext with Python and am using operator _ or _( to indicate translatable strings (which I have set in Poedit under Properties - Sources Keywords).

I have also set paths of my translatable sources to . (all files in that directory) and even tried setting those .txt files specifically for extracting.

My text file looks like this (one line of one file):

_(Koliko je 2/0?);_(0):_(ni definirano):_(2);_(ni definirano)

I tried to find which document type's Poedit extracts text from but did not find anything other than "from source" - should it be able to extract from .txt files or not? If not, how should I name them?

As I said, it does extracts strings from my .py files so it is working otherwise.

2

2 Answers

0
votes

Poedit can't magically know the syntax of your homegrown file format, so simply adding .txt files can't possibly do anything. You'll have to write a custom extractor (see how xgettext works for reference) or switch to some standard syntax:

  1. Be sufficiently similar to a supported programming language, such as C (where as luck would have it, ; and : are both valid syntax elements, although using e.g. , instead of : would be safer):

    _("Koliko je 2/0?");_("0"):_("ni definirano"):_("2");_("ni definirano")

  2. Use XML-based format, where xgettext supports extraction rules described with ITS.

0
votes

I was confronted with the same problem when trying to extract strings to be translated from an options.txt file in a WordPress plugin. The only solution I found was to copy that options.txt file to options.php, which PoEdit was able to search for strings. When the translation operation is finished, the options.txt file can then be deleted.