How to generate a .po file?
Asked Answered
Y

4

19

On Windows using WAMPserver (Apache, MySQL, PHP) I have the following:

//test.php
if (!defined('LC_MESSAGES'))
define('LC_MESSAGES', 6);

$lang = "sv";
putenv("LANG=$lang");
setlocale(LC_ALL, $lang);

$domain = "messages";
bindtextdomain($domain, "./locale");
textdomain($domain);

echo _("This is a string");

It works fine, i.e. it outputs "This is a string" which means I have gettext correctly setup up.

But HOW in the world do I create a .po file?

I downloaded Poedit but I can't see how to make this happen with that software.

Any help is greatly appreciated!

Ybarra answered 25/3, 2010 at 9:53 Comment(1)
I found this tutorial helpful >>Gettext & PoEdit>>Aught
U
11

PoEdit is the tool to create the .po file. You have to do a little configuration with it and it's not the easiest. The way it should work is that it finds all the text in your source code that's wrapped in the marker string that you configure. This becomes the source text that you give to your translator. They then translate it into the target language(s) and save the translation files and return them to you. You then dump those files into a special directory in your php application and whenever the gettext extension sees one of the translation strings it fetches the appropriate translation.

I can probably help more if you show some details about where you got hung up with poedit.

Umeko answered 26/3, 2010 at 0:33 Comment(5)
Thx, I managed to sort it out. The problem was that it was not clear on how to set the basepath(s). And the interface is too old to be intuitive enough to understand how to create a new path. :)Ybarra
Most important are the path (absolute path) settings in your catalog file, otherwise Poedit isn't able to use gettext() from source files.Snorkel
@VolkerE. advise is incorrect in one aspect: you should use relative, not absolute paths, because the former would be unportable to other machines. Better yet, use Poedit 1.8beta3 (or newer) that fixed the absolutely terrible (and I’m saying this as Poedit author) interface for setting sources path and allows you to just drag the relevant directories over.Prelature
@VáclavSlavík Thanks for hinting at poedit.net/download Poedit 1.8beta3 – the source path interface is much improved, before it wasn't clear to many GUI users on how to set relative paths, that was the reason for my presumably wrong comment on setting paths absolutely.Snorkel
@VolkerE. Oh, I don’t blame you at all, it’s exactly as you say: the old UI was so impressively bad that many people figured absolute paths were the only way to make it work. About time I fixed that.Prelature
L
8

FOR php:

I have a file like ---- test_1.php ----

<?php
  echo _("Test phrase");
  echo gettext("Test phrase two");
  // NOTE: _ == gettext()
?>

File -> New catalog... In the "Source paths" tab, you have to click in New Folder, Add the path of the folder in which do you have the file (in this example test_1.php)

... They caught ALL the strings that get invoked with gettext() or _() ... The useful for those function is explained here http://www.php.net/manual/es/function.gettext.php

AND... If do you use Apache (for example in Xampp), please, Stop and Start (Restart) it when do you wanna test a new change in a defined language with gettext(), in another way the change will not be affected

Lustral answered 21/11, 2012 at 1:52 Comment(0)
M
0

There're many tools, such as Poedit. In PHP, it's handled by the Gettext extension.

See also:

If you are any problems with Poedit, feel free to give some details.

Mutation answered 25/3, 2010 at 11:8 Comment(0)
P
0

Use xgettext to generate the file out of source codes.

xgettext -D src/ -o ./locale/id_ID.po

Then you may edit the id_ID.po file.

You can use provided pre-compiled binary such as this.

Phrygian answered 5/7, 2020 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.