Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a .po file?

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!

like image 870
tobefound Avatar asked Mar 25 '10 09:03

tobefound


People also ask

What is a .po file?

A . PO file is a portable object file, which is text-based. These types of files are used in commonly in software development. The . PO file may be referenced by Java programs, GNU gettext, or other software programs as a properties file.

How do I open a .po file?

To open PO and POT files, you can use any text editor that supports the format (such as Notepad, Sublime Text, or Notepad++), use specialized software (like Poedit), or Localazy - the online translation management system explicitly made for working with translation file formats.

What is a PO file WordPress?

PO (Portable Object) files Every translator will take the POT file and translate the msgstr sections into their own language. The result is a PO file with the same format as a POT , but with translations and some specific headers. There is one PO file per language.

What is the use of Poedit?

Poedit is a software to translate your WordPress themes and plugins. It is not a plugin, but a tool external to WordPress. There is a free version and a premium version, starting at €29.99 (i.e ± $34) for one year of use.


2 Answers

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.

like image 71
Colleen Kitchen Avatar answered Sep 20 '22 17:09

Colleen Kitchen


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

like image 38
Lupen Avatar answered Sep 18 '22 17:09

Lupen