1
votes

so the issue is the following. I am converting a site from a content array for each language to a gettext site with 2 additional to the original languages.

So my base language is es_MX and I have en_US and fr_FR translations.

I use the following parameters in .htaccess to pass info on the locale:

RewriteRule     ^/?$            index.php?es=./&en=./en/&fr=./fr/&locale=es_MX [L]
RewriteRule     ^en/?$          index.php?es=./&en=./en/&fr=./fr/&locale=en_US [L]
RewriteRule     ^fr/?$          index.php?es=./&en=./en/&fr=./fr/&locale=fr_FR [L]

So, when I check the $_GET parameters everything is received correctly.

Case 1: Default es_MX

Array
(
    [es] => ./
    [en] => ./en/
    [fr] => ./fr/
    [locale] => es_MX
)

Case 2: en_US

Array
(
    [es] => ./
    [en] => ./en/
    [fr] => ./fr/
    [locale] => en_US
)

Case 3: fr_FR

Array
(
    [es] => ./
    [en] => ./en/
    [fr] => ./fr/
    [locale] => fr_FR
)

So, after that what I do in order to have several language variables for use at say social network plugins or attributes, I have the following conditions:

if(!$_GET["locale"] || $_GET["locale"] == "es_MX") {
    $locale = "es_MX";
    $locale_general = "es_LA";
    $lang = "es";
    $isolang = "es-419";
    $htlang = "es-MX";
} else if($_GET["locale"] == "en_US") {
    $locale = "en_US";
    $locale_general = "en_US";
    $lang = "en";
    $isolang = "en";
    $htlang = "en-US";
} else if($_GET["locale"] == "fr_FR") {
    $locale = "fr";
    $locale_general = "fr_FR";
    $lang = "fr";
    $isolang = "fr";
    $htlang = "fr-FR";
}

After that I initialize the locale using:

putenv("LC_ALL=".$locale.".utf8");
setlocale(LC_ALL, $locale.".utf8");
bindtextdomain("hacienda", "./locale");
bind_textdomain_codeset("hacienda", "UTF-8");
textdomain("hacienda");

My locales are located at: - English (./locale/en_US/LC_MESSAGES/hacienda.mo) - French (./locale/fr_FR/LC_MESSAGES/hacienda.mo)

I ran exec("locale -a",$output) and the site shows a bunch of locales among which are several fr_FR entries including fr_FR.utf8.

The generated html is:

<html class="no-js" lang="fr" xml:lang="fr" itemscope itemtype="http://schema.org/Hotel"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
...

I tried renaming the locale file also created a new one but it doesn't seem to get the french translations. Any idea what might be causing that?

1
Everything you've shown us seems to be symmetric between the en_US and fr_FR locales. Did you check the permissions on the locale/*/LC_MESSAGES/hacienda.mo files, and on the directories?Guntram Blohm
I actually copy/pasted the en_US folder to fr_FR and just changed some strings so even if I hadn't changed them it should appear as if it were english.Mihail Minkov

1 Answers

0
votes

That's very embarrasing, but I missed to add _FR to $locale = "fr"; now that I fixed it to $locale = "fr_FR"; it's working. Sorry for the waste of time.