Recent Topics

How to extract POT file from PHP source?

Started by on Feb 14, 2008 – Contents updated: Feb 14, 2008

Feb 14, 2008 04:50    

Hi

I'm trying to translate plugins, but only some of them have a pot file (even if they use gettext method)

Can I somehow extract or get these POT files from php modules?

Feb 14, 2008 05:18

In addition it'd be cool to know how to turn a messages.po into a matching _global.php without doing it by hand.

Feb 14, 2008 10:30

3 easy steps

- rename de_DE or fr_FR directory in /locale to the one you need (ru_RU)
- replace an existing .po file with yours
- run built-in script from Global settings -> Regional to extract it

Feb 14, 2008 13:25

Okay cool. I saw that on the localization page in the manual but didn't know it would work for plugins. Kinda thought it was only for the program itself.

Thanks!

Feb 14, 2008 20:13

All translations I sent to you guys were generated this way. ;) And they all work

Feb 14, 2008 21:41

sam2kb, but then you probalby haven't translated 3rd party plugins, I guess.. :)

Feb 14, 2008 22:01

I think he did because he sent me a ru_RU folder (with _global.php and the other folder with messages.po) for my creative commons plugin. In truth I simply suspect it works because I have no idea how to test it.

Maybe it's an undocumented feature :)

Feb 14, 2008 22:20

If you wanna test it on your system just change the lang in your browser to RU

Feb 14, 2008 23:05

sam2kb, sorry. Of course it was you that send me to this thread even.. so I should have known that it works and looked closer at the method.. :)
It's quite hackish though.. maybe there should be some upload script to generate the file in the locales tools tab.. :)

Mar 29, 2008 12:43

I finally found a solution.
If you want to create a POT file in Windows, download the following archives and unzip them in one folder, name it gettext.

http://ftp.gnu.org/gnu/gettext/gettext-runtime-0.13.1.bin.woe32.zip
http://ftp.gnu.org/gnu/gettext/gettext-tools-0.13.1.bin.woe32.zip

Open a command prompt and navigate to the bin folder
cd c:\gettext\bin

Run this command to extract translatable strings from c:\file.php

xgettext.exe --no-wrap --add-comments=TRANS --copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/ --output=c:\messages.pot --keyword=T_ --keyword=NT_ --keyword=TS_ c:\file.php

You should now see a messages.pot in c:\

Mar 31, 2008 00:49

sam2kb, another way to get the "good tools" on windows is installing cygwin (http://www.cygwin.com/), which provides a lot of useful GNU tools.
This is a must-have on windows IMHO.

btw: you should be able to use the /gettext/xg.php script from b2evo with the "extract" option (then).

Jun 13, 2009 11:47

sam2kb wrote:

I finally found a solution.
If you want to create a POT file in Windows, download the following archives and unzip them in one folder, name it gettext.

http://ftp.gnu.org/gnu/gettext/gettext-runtime-0.13.1.bin.woe32.zip
http://ftp.gnu.org/gnu/gettext/gettext-tools-0.13.1.bin.woe32.zip

Open a command prompt and navigate to the bin folder
cd c:\gettext\bin

Run this command to extract translatable strings from c:\file.php

xgettext.exe --no-wrap --add-comments=TRANS --copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/ --output=c:\messages.pot --keyword=T_ --keyword=NT_ --keyword=TS_ c:\file.php

You should now see a messages.pot in c:\

I followed your very simply instructions but i get an error saying:
This application has failed to start because iconv.dll was not found.
Re-installing the application may fix this problem.

I thought maybe adding the c:\gettext\bin folder to system variables might help but it didn't. :roll:

Jun 13, 2009 17:09

If you have Poedit installed, try this.

Create a *.bat file with the following content.
Run the file in plugin/skin folder, it creates a list of all *.php files and extracts strings from them, then it creates locale directories with initial content.

@echo off

echo Generate file list.
dir /b /s *.php > %TMP%/files.txt

echo Create locales folder.
mkdir locales locales\ru_RU locales\ru_RU\LC_MESSAGES

echo Extract strings.
"C:\Program Files\Poedit\bin\xgettext.exe" -f %TMP%/files.txt --no-wrap --add-comments=TRANS --copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/ --output=locales\messages.pot --keyword=T_ --keyword=NT_ --keyword=TS_

echo Copy initial messages.po file
copy locales\messages.pot locales\ru_RU\LC_MESSAGES\messages.po

echo Create blank _global.php
echo qwerty> locales\ru_RU\_global.php

If locale directories already created you should run this *.bat instead

@echo off

echo Generate file list.
dir /b /s *.php > %TMP%/files.txt

echo Extract strings.
"C:\Program Files\Poedit\bin\xgettext.exe" -f %TMP%/files.txt --no-wrap --add-comments=TRANS --copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/ --output=locales\messages.pot --keyword=T_ --keyword=NT_ --keyword=TS_

Jun 13, 2009 23:28

--copyright-holder="Francois PLANQUE" --msgid-bugs-address=http://fplanque.net/

That part is only good if you happen to be Francois and your web site is fplanque.net ;) Other than that, this .bat is how I make message.pot files for my plugins.

Oct 26, 2009 13:09

Hey Blueyed.
This is Jenny Newbie here, the plug-in files can not be easily modified from php to other format, as they ae inbuilt specified. The information about B2evolution is very important for this issue. Thank you for giving me information.

Oct 26, 2009 21:24

Jenny, I do not understand your problem neither your question. Please elaborate.

Mar 03, 2010 23:39

That is very good the know. Thanks for sharing

Jess

Apr 09, 2010 11:05

Good!It is very useful,thank you for sharing the post.


Form is loading...

Build your own website! – This forum is powered by b2evolution CMS, a complete engine for your website.