Forum OpenACS Q&A: Re: Webpage Translation - Parsing i18n messages

Collapse
Posted by Iuri Sampaio on
Gustaf,

In fact Apache does show errors related HTTP_ACCEPT_LANGUAGE

[Sun Jun 29 14:45:19 2014] [error] [client 208.115.111.66] PHP Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /var/www/natopia/app/Config/core.php on line 973
[Sun Jun 29 14:45:22 2014] [error] [client 208.115.111.66] PHP Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /var/www/natopia/app/Config/core.php on line 973
[Sun Jun 29 14:56:02 2014] [error] [client 66.249.65.232] PHP Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /var/www/natopia/app/Config/core.php on line 973
[Sun Jun 29 15:13:24 2014] [error] [client 66.249.65.219] PHP Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /var/www/natopia/app/Config/core.php on line 973

Moreover I installed php5-intl then I added a PHP call to set HTTP_ACCEPT_LANGUAGE accordingly (i.e. Locale::setDefault($lang);), within PHP website configuration files.

It seems to be working fine now. Apache doesn't return errors anymore. Plus, I wrote echo($_SERVER['HTTP_ACCEPT_LANGUAGE']);
to confirm that HTTP_ACCEPT_LANGUAGE is assigned properly.

You also can see its output at the very top left of page: http://dev.natopia.com/Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife

I noticed that independently on what idiom I select HTTP_ACCEPT_LANGUAGE value doesn't change. (i.e. "en-US,en;q=0.5"). Its value permanently is "en-US" even if I change the language of the website.

Should I expected it to switch laguange when the website language is change to en, es or pt?

Furthermore, OACS page's still called only in en_US, even though the website is in pt-BR.

On another front, to set Accept-Language to the desired language within javascript code, I should add an AJAX chunk which is triggered by the link that calls the popup to show up. Thus, it would request http with headers properly set. As in.

var locale = escape(document.getElementById("locale").value);
xmlhttp.setRequestHeader("Accept-Language", locale);

But, unfortunately it didn't work out as expected.

function loadXMLDoc() {
var xmlhttp;
var locale = "pt-BR";

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}

xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlhttp.setRequestHeader("Accept-Language", locale);
xmlhttp.setRequestHeader("User-Agent", "XMLHttpRequest");

xmlhttp.open("POST","http://ecommerce.natopia.com/natopia/core/check-availability-confirmation",true);
xmlhttp.send();
}

Collapse
Posted by Gustaf Neumann on
if i browse to http://dev.natopia.com/Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife i see the "accept-language" settings from my browser in the first line. When i change the preferred language in my browser from en-us to pt, the value alters correctly (but the content of this page stays pt). When i click on the us-flag, the displayed language switches to en. I see from firebug that clicking on the flag causes cookie named "language" to be set, which seems to have higher precedence than accept-language.

So, it looks to me as:
a) setting "accept-language" has no effect on the locale of that site (setting it from a js-request won't change anything)
b) the locale is determined via cookie

Therefore, I would recommend to include "Cookie: language=pt" to the js request.

I am just making guesses from the distance. You should know your code in detail.

Hop this helps
-gustaf neumann