Creating a New Format Support

7 views
Skip to first unread message

João Angelo de Franco

unread,
Mar 28, 2012, 1:04:42 PM3/28/12
to transif...@googlegroups.com
I'm starting to create a new format support, but I couldn't find a guide or a wiki page on how.

Actually, the Transifex will need to import only the text betwen tags of the mes line:

mes "Welcome to Test"

Nothing more. How can I build a new format handler for it?

rtnpro

unread,
Mar 29, 2012, 8:11:57 AM3/29/12
to transifex-devel
Hi,
In it's simplest form a format handler at Transifex should subclass
from 2 classes:
1. transifex.resources.formats.core.Handler
2. and a Compiler Factory, e.g.
transifex.resources.formats.compilation.FillEmptyCompilerFactory
There are other compiler factories available too.

Then, you override the _parse() method in the handler. In the _parse()
method, you add the code to parse your file to generate source,
translation strings. In your case,
comment = ""
context = ""
once you have a source, translation pair, you save them like below:
self.stringset.add_translation_string(source,
self._unescape(translation), comment=comment, context=context)
If you have some special unescaping (during import) and escaping
(during export) to be done for the file format, then override methods
_escape(self, s) and _unescape(self, s) methods of the handler.

You must generate a template to be saved in the database in case the
file is uploaded in the source language, i.e., is_source=True
In your case, the template should look like:

mse "8bb101bb2cd76582a2c301a69f3c515b_tr"

This template is used to compile the file for download.
The hash is generated in the following way:
from transifex.resources.formats.utils.hash_tag import hash_tag
"%(hash)s_tr" % {'hash': hash_tag(source, context)}

The _parse() method must always return a template (which may be "" in
case of translation files). However, it must be a proper template as
above for source files.

I hope I was able to explain things a bit. You can also refer to this
code for some help https://bitbucket.org/indifex/transifex/src/694d74d112e6/transifex/resources/formats/strings.py

In case you have any query, feel free to ask.

Thanks,
Regards,
rtnpro
Reply all
Reply to author
Forward
0 new messages