Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Extract .po string from .volt file

Hi, How to extract string from .volt files ? With poedit or this one https://www.icanlocalize.com/tools/php%5scanner don't work.. the format of string used is:

{{ t._('My phrase') }}

thanks



4.8k
edited May '16

Can you get more information about the problem? In what sense and why does "extract"?

If you want to create the *.po localization-file in your project, you should move all of strings with the text in this file and use the translate component in the .volt like this.

{{ t._('TheConstantForTranslation') }}

You can make it manually. In my opinion, it's will be easier and faster then searching the automatic method. Good luck!



1.1k
edited May '16

Hi, Is not ideal to create manually the .po files for large project. Is preferable and good practice to extract phrase directly from files, as poedit offer this: http://www.tiikoni.com/tis/view/?id=1413717

I think that this is the more faster and easier way than manually. Otherwise is like that you need to do double work.

At the moment the only workaround that I found is to extract from cached files.

I found also this Twig extractor: https://github.com/umpirsky/Twig-Gettext-Extractor, I need to test using volt, maybe just adding different extension can work.

I guess if someone had already solve this problem by preparing something custom for volt.

Thanks!



996

I think you mean that poedit is not parsing .volt files? If yes, you can edit poedits settings.

  1. Open poedit
  2. Edit -> Settings
  3. Switch to Parser Tab
  4. Select PHP and click on edit
  5. Add *.volt to the list


1.1k
edited May '16

Thanks for this tip, but seem that don't help. Do you tested already? The parser of po edit search for php tag open (<?php) and php tag close (</php>) This is error message:

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: warning: file 'view.volt' extension 'volt' is unknown; will try C

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found


I think you mean that poedit is not parsing .volt files? If yes, you can edit poedits settings.

  1. Open poedit
  2. Edit -> Settings
  3. Switch to Parser Tab
  4. Select PHP and click on edit
  5. Add *.volt to the list


996

Try a different Parser like C++

Thanks for this tip, but seem that don't help. Do you tested already? The parser of po edit search for php tag open (<?php) and php tag close (</php>) This is error message:

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: warning: file 'view.volt' extension 'volt' is unknown; will try C

Sat May 21 12:50:44 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read view.volt: Start tag expected, '<' not found


I think you mean that poedit is not parsing .volt files? If yes, you can edit poedits settings.

  1. Open poedit
  2. Edit -> Settings
  3. Switch to Parser Tab
  4. Select PHP and click on edit
  5. Add *.volt to the list


1.1k

Try a different Parser like C++

Can you please tell me more how to do this? Thanks

I use this bash script to parse translations:

find . -path './vendor' -prune -o -printf '%p\n' | sort -n | grep '\.php$' | xargs xgettext --from-code=UTF-8 --default-domain=default -o ./locale/template.pot

The idea behind it is that the Volt engine generates php files for final use, so I get the phrases from there, not the .volt files. You would have to have all pages visited ofc, or a script that compiles all volt files to the cached php.



996
  1. Open poedit
  2. Edit -> Settings
  3. Switch to Parser Tab
  4. Select C++ and click on edit
  5. Add *.volt to the list

Try a different Parser like C++

Can you please tell me more how to do this? Thanks



1.1k
edited May '16

Thanks for your suggestion, but don't work. This is just a few of similar error messages:

Wed May 25 19:18:07 2016: cover.volt:2: warning: unterminated character constant

Wed May 25 19:18:08 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: cannot read login.volt: Start tag expected, '<' not found

Wed May 25 19:18:08 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: warning: file 'register.volt' extension 'volt' is unknown; will try C


Open poedit
Edit -> Settings
Switch to Parser Tab
Select C++ and click on edit
Add *.volt to the list


1.1k

Yes from cache files work fine, but I would like to extract from volt file.

I use this bash script to parse translations:

``` find . -path './vendor' -prune -o -printf '%p\n' | sort -n | grep '.php$' | xargs xgettext --from-code=UTF-8 --default-domain=default -o ./locale/template.pot ```

The idea behind it is that the Volt engine generates php files for final use, so I get the phrases from there, not the .volt files. You would have to have all pages visited ofc, or a script that compiles all volt files to the cached php.



996
Accepted
answer
edited Jun '16

This Works:

  1. Open your Catalog
  2. Open Edit -> Settings
  3. Go to parsers Tab
  4. Remove all parser
  5. Add new Parser, then add following

  1. Volt
  2. *.volt
  3. xgettext --language=Python --force-po -o %o %C %K %F
  4. -k%k
  5. %f
  6. --from-code=%c

After this i could parse volt files



1.1k
edited May '16

Hi, thanks for suggestion, but I have already try that. I try again now and still not working, this is a few error msg:

Thu May 26 10:06:55 2016: page.volt:2: warning: unterminated character constant

Thu May 26 10:06:56 2016: posts.volt:83: warning: unterminated string

Thu May 26 10:06:56 2016: /Applications/Poedit.app/Contents/PlugIns/GettextTools.bundle/Contents/MacOS/bin/xgettext: Non-ASCII character at search.volt:83.

Thu May 26 10:06:56 2016: Please specify the source encoding through --from-code or through a comment

Thu May 26 10:06:56 2016: as specified in http://www.python.org/peps/pep-0263.html.

Thu May 26 10:06:56 2016:

Thu May 26 10:06:56 2016: Entries in the catalog are probably incorrect.

Thu May 26 10:06:56 2016: Updating the catalog failed. Click on 'Details >>' for details.

Just a note: point 4. Remove all parser

First of all I need to go to "Poedit > Preferences > Extractor" (maybe because I am using a mac is different?)

Second thing is that I don't delete existing extractor (what you call "parser").

Screenshot:

screen 1: http://www.tiikoni.com/tis/view/?id=b299db5

screen 2: http://www.tiikoni.com/tis/view/?id=b84e3af



996

The error only says you have to define the encoding of your catalog before you try to extract the strings.



1.1k

Yes, you are right, work fine after adding encoding. I get different error message, but seem that all phrase are extracted.

Big thanks!

The error only says you have to define the encoding of your catalog before you try to extract the strings.