Question

I am trying gettext and poedit for the first time after reading an article about it. Gettext is enabled - that's not the problem. The problem is when I use poEdit. I will start showing you my files:

#localization.php

$locale = "de_DE";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");

#test.php

echo _("Welcome to my test page");

I have opened poEdit and saved a messages.po-file. Now, poEdit should scan files by itself and show all the strings, that should be translated. However, nothing seems to appear. This is my paths:

C:\Users\HS\SkyDrive\Webkodning\wamp\www\test\ <- Files in this folder
C:\Users\HS\SkyDrive\Webkodning\wamp\www\test\locale\de_DE\LC_MESSAGES <- messages.po in this folder

I think that the problem is the path (when saving the catalog). How should the path be like? Or maybe my path inside the bindtextdomain()-function i wrong. I really hope that I can receive some help on this area.

Thanks in advance.

Was it helpful?

Solution

First possibility:

  1. You have to check the catalog properties (Open the .po file in POedit program then choose Menu 'Catalog'->'Properties' or simply just Alt+Enter, and check the Sources Path
  2. Check the base path is correct refer to C:\Users\HS\SkyDrive\Webkodning\wamp\www\test\
  3. Make sure youu already add "." (without quotes) in paths

Second possibility:

When you test the code use the lower string parameter for locale (de_de not de_DE) like this htttp:\url\test.php?locale=de_de

Third possibility:

Make sure poedit already generate the .mo file and if it's already then try to restart your WAMP server

Hopefully it will help

OTHER TIPS

Ok, so you want PoEdit to scan your files for you instead of using the gettext utility xgettext?

Well, start PoEdit and go to Catalog -> Update from sources. If it is disabled you haven't told PoEdit where to look so go to Catalog -> Properties and select the Source paths tab. You may also go to the Sources keywords tab and add your translation keyword(s).

An important thing to keep in mind: Do not forget to set the charset in .po file! For example:

"Content-Type: text/plain; charset=UTF-8\n"

Then PHP will be able to find the .mo file you generated, using msgfmt, from the .po file WITH CHARSET SET.

Because of this I've wasted a lot of time debugging my code, testing every single little changes people suggested over this manual and Internet:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top