Volt gettext parser is now available through xgettext-template

The npm package xgettext-template as of v2.3.0 now includes Volt template parsing for gettext messages. I maintain a near identical development branch of this software with xgettext-webird but I recommend that you use the original package.

So what can you do with this?

You can use this node tool to extract the gettext messages from a Volt template.

{{ t('This message is in English') }}

and this:

{%- set menus = [
  'features': t('Features'),
  'admin': t('Admin')
] -%}

This message is then pulled out of the template and your translator (person) can then convert that message into another language.

With this xgettext-template message extractor you can pull messages out of many of the Jinja style templates, so; Nunjucks, Swig, Jinja, Volt, etc. You can use a similar templates for the front and back end to help keep your mind thinking in a similar way as you move between different parts of the stack. Take a look at my Webird system where I am using Nunjucks templates on the front end and Volt templates on the backend.

I'm trying to translate volt files using xgettext-template or webird but none of them are working. I'm just getting the PHP translations...

I was using translator directly from dependency injector into my views:

{{ translate.t('test') }}

but after some reading, I've tried:

{{ t('Todos') }} {{_ 'Todos' }} {{ngettext 'Todos' }}

But none of them are working when using PoEdit for translate detection, and I'm not receiving any error message. I've followed these instructions: https://github.com/perchlayer/xgettext-webird.

Could you tell me what I'm doing wrong?

thanks, pablo.



48.3k
edited May '16

Ok so to start with use xgettext-template moving forward.

Did you make sure that you Volt templates are in the lookup path set in the .po file?

Another thing to look for would be if you have those same keywords registered in your .po file.

Try cloning Webird and seeing if you can extract messages from the system by opening a PO file in app/locale. It uses all relative paths so it should just work.

Also you can just open up one of the PO files to compare it to your setup.



48.3k

I just verified that everything is working in Webird. A message pops up that says it is using the Volt parser. So likely you do not have it installed correctly in PoEdit. Maybe the installed parser box is unchecked, etc.

Ok, I'm using again xgettext-template. I've created a parser called "Volt", already checked, with the following settings:

Volt *.volt xgettext-template --force-po -o %o %C %K %F -k %k %f --from-code=%c

In my catalogue properties I've created these keywords:

t _

and nothing is found, but If I add "translate.t" to the keywords, then it fails.

My volt files are under the same root directory than my php files, but in diferent subdirectories.

This works:

xgettext-template --force-po -o messages %C %K %F -D <project_path> -L Volt -k translate.t

But I cannot make it work from PoEdit. If I add a keyword "translate.t" to the catalogue or If I add a "-k translate.t" to the xgettext-template line, it fails after processing all the volt files.

This is the error:

/Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/msgcat: el fichero de entrada '/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/35extracted.pot' no contiene una línea de encabezado con la especificación del conjunto de caracteres

Orden errónea: msgcat --force-po -o "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/43merged.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/35extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/36extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/37extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/38extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/39extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/40extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/41extracted.pot" "/var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poeditiZagfW/42extracted.pot"

Error al combinar los catálogos de Gettext.



48.3k

Try using the full xgettext-template path in Poedit. I use Linux for message extraction so that could have something to do with it.

This is the header of the file where it fails:

less /var/folders/rb/cz90h5717879gysw_0jvb5kc0000gn/T/poedituDxffJ/35extracted.pot msgid "" msgstr "Content-Type: text/plain;\n"

This file has many translations after this line, but they are not shown in the poedit

I've solved the problem without PoEdit, as the problem was using msgcat, this is what I did:

1) Run PoEdit and create a .po file, retrieving only translations from php files, and put them into a php_messages.po file

2) Execute

xgettext-template --force-po -o volt_messages.po %C %K %F -D <project_path>-L Volt -k translate.t --from-code utf8

3) Replace the first to lines from the beginning of volt_messages.po file and write the following: msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n"

4) Concat .po files

msgcat -o messages.po php_messages.po volt_messages.po

5) Remove conflicting lines "#-#-#-#-# php_messages.po (<project_name>) #-#-#-#-#\n" "#-#-#-#-# volt_messages.po #-#-#-#-#\n" "Content-Type: text/plain; charset=UTF-8\n”

  1. Open messages.po with PoEdit and compile it.

Following these steps I can get all my translations together, any other way of getting my translations from any single volt file gives me an error.

edited May '16

Hav you trie to run poedit against the compiled template files ? see parameter compiledPath in https://docs.phalconphp.com/en/latest/reference/volt.html#setting-up-the-volt-engine