Question

I've used Poedit (running on Win7) to generate .mo/.po files to make a Russian version of a web page using PHP gettext. When I display the Russian version of the page, all the characters are shown as black diamonds/squares.

Here is a sample web page demonstrating the problem:

http://cthorn.co.uk/localization/index.php

... and here is the Russian version:

http://cthorn.co.uk/localization/index.php?locale=ru_RU

The code for index.php is:

<?php require_once("locale/localization.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>Test</title>
    </head>

    <body>
        <p><? echo _("This is the text to be translated."); ?></p>
    </body>
</html>

The code for the file localization.php is:

<?php
    $locale = "en_GB";
    if (isSet($_GET["locale"])) $locale = $_GET["locale"];
    putenv("LC_ALL=$locale");
    setlocale(LC_ALL, $locale);
    bindtextdomain("messages", "./locale");
    textdomain("messages");
?>

The directory structure is:

 - localization
    - locale
       - ru_RU
          - LC_MESSAGES
               messages.mo
               messages.po
         localization.php
      index.php

In Poedit I set both "Charset" and "Source code charset" to UTF-8. "Language" is set as Russian and "Country" is set as RUSSIAN FEDERATION.

I made sure that the Russian text was copied from a UTF-8-encoded text file before being pasted into Poedit.

What am I missing?

Here is messages.po copied out of Notepad++:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-11-16 10:49-0000\n"
"PO-Revision-Date: 2011-11-16 10:49-0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: C:\\websites\\cthorn.co.uk\\live\n"
"X-Poedit-Language: Russian\n"
"X-Poedit-Country: RUSSIAN FEDERATION\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-SearchPath-0: .\n"

#: localization/index.php:10
msgid "This is the text to be translated."
msgstr "Это текст для перевода."

Ah sorry - download the files from:

cthorn(dot)co(dot)uk/localization/locale/ru_RU/LC_MESSAGES/messages.mo cthorn(dot)co(dot)uk/localization/locale/ru_RU/LC_MESSAGES/messages.po

(I can only post two links as I'm a n00b)

Was it helpful?

Solution

Make sure everything is in utf-8 and it will work great.

different Content-encodings always end up as a real pain in the a**

OTHER TIPS

Well, the russian text on your page is ISO-8859-5. The question is how did it end to be in that encoding :) Can you show your .po file?

UPD. Everything in your files looks fine. The only thing I can think of is try this:

    setlocale(LC_ALL, $locale.'.utf8');
    bind_textdomain_codeset("messages", 'UTF-8');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top