I'm trying to use PHP’s get text
to add multilanguage support to my website. Unsuccessful so far, and I have no idea why.
In my i18n.php
file I have this:
<?php
$locale = 'pt_PT.utf8';
$locale_dir = './locale';
$domain = 'messages';
setlocale(LC_ALL, $locale);
putenv("LANG=$locale");
putenv("LANGUAGE=$locale");
bindtextdomain($domain, $locale_dir);
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
?>
Then, in ./locale/pt_PT.utf8/LC_MESSAGES/messages.po
:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION
"
"Report-Msgid-Bugs-To:
"
"POT-Creation-Date: 2013-11-23 20:31+0000
"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>
"
"Language-Team: LANGUAGE <LL@li.org>
"
"Language: pt_PT.utf8
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
#: index.php:12
msgid "E-mail"
msgstr "Endereço electrónico"
#: index.php:13
msgid "Password"
msgstr "Palavra-chave"
#: index.php:14
msgid "Password (again)"
msgstr "Palavra-chave (novamente)"
#: index.php:15
msgid "Login"
msgstr "Entrar"
I then generate the .mo
file:
msgfmt -o ./locale/pt_PT.utf8/LC_MESSAGES/messages.mo ./locale/pt_PT.utf8/LC_MESSAGES/messages.po
It seems that php requires that the locales are installed in linux systems, so I checked with locale -a
:
C
C.UTF-8
de_AT.utf8
...
en_AG
...
es_AR.utf8
...
POSIX
pt_BR.utf8
pt_PT.utf8
...
i18n.php
is my first include in the index.php
file, but none of the messages show. Any idea what I'm missing?