xgettext with a custom input format

499 Views Asked by At

xgettext is capable of extracting strings for translation from a variety of source languages.

   -L, --language=NAME
          recognise  the  specified  language (C, C++, ObjectiveC, PO,
          Shell, Python, Lisp, EmacsLisp, librep, Scheme, Smalltalk,
          Java, JavaProperties, C#, awk, YCP, Tcl, Perl, PHP, GCC-source,
          NXStringTable, RST, Glade, Lua, JavaScript, Vala, Desktop)

(your exact list may vary by platform)

It also guesses the type based on the file extension, so:

$ xgettext -o out.pot in.php

will use the PHP parser without needing -L PHP.

However, I wish to translate files that aren't in any of those languages. Is it possible to submit a list of strings into xgettext directly? Or to teach it a new language?

For example, consider some Handlebars templates using a custom helper function __, like so:

<title>{{__ 'My Website'}}</title>

It's possible to extract all the strings from the files using grep:

$ grep '\{\{__ (.+?)\}\}' -Ero views
views/index.hbs:{{__ 'My Website'}}

But is there any way of feeding this information into xgettext to produce a valid pot file?

Note: while I'd appreciate a solution to this specific case, the question is really about the general case of an unknown language.

0

There are 0 best solutions below