I'm working on a multilanguage PHP website that uses Poedit for translations and I'm having problems with a specific language, that is Spanish.
I will start saying that in the server (after website is published) both languages work fine but in my DEV environment only english is translated.
FYI, spanish locales were not installed on my Ubunto system, so I have installed them via: sudo apt-get install language-pack-es and generated relevant stuff via: sudo locale-gen es.
I have the next folder structure under my web:
languages => en_US => LC_MESSAGES => .po + .mo (compiled) files
languages => es_ES => LC_MESSAGES => .po + .mo (compiled) files
and the set_locale.php file is the next:
<?php
// Include the Composer autoloader
require_once 'vendor/autoload.php';
// Update include path
require_once 'Audero/SharedGettext/SharedGettext.php';
$translationsPath = 'languages';
$language = 'es_ES'; //en_ZM
if (isset($_GET['lng'])) {
$getLocale = $_GET['lng'];
if($getLocale=="en") {
$language="en_US";
}
}
$domain = 'audero';
putenv('LC_ALL=' . $language);
setlocale(LC_ALL, $language);
try {
$sharedGettext = new Audero\SharedGettext\SharedGettext($translationsPath, $language, $domain);
// Create the mirror copy of the translation and return the new domain
$newDomain = $sharedGettext->updateTranslation();
$sharedGettext->deleteOldTranslations();
// Sets the path for the current domain
bindtextdomain($newDomain, $translationsPath);
// Specifies the character encoding
bind_textdomain_codeset($newDomain, 'UTF-8');
// Choose domain
textdomain($newDomain);
//die(print_r("", true ));
} catch(\Exception $ex) {
echo $ex->getMessage();
}
?>
And I translate texts in the following way:
...
<title><?php echo _("home_title"); ?></title>
...
But for spanish I get the key (home_title following the the example) but not the translation.
Any help?
Thanks.