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

Collapse
Posted by Benjamin Brink on
Hi Iuri,

Answer to your last question first:

No, don't put check-availability-content in /packages/package-name/lib because the server will not directly serve pages from lib.

Notice:

http://ecommerce.natopia.com/natopia/core/check-availability2

and

http://ecommerce.natopia.com/natopia/core/check-availability

appear to have same content. This is good.

However,

http://ecommerce.natopia.com/natopia/core/check-availability-content

has different content. This is good. This means that you have two versions of the page. One version to share with external pages: check-availability-content and one version to serve directly: check-availability

check-availability-content page has only the content you want to request with luxury-eco-lodge-in-the-amazon-wildlife page, because it doesn't include the wrapping html,head,body tags and extra content.

The 404 error suggests that one of the requests made by luxury-eco-lodge-in-the-amazon-wildlife page is missing.

Please verify that luxury-eco-lodge-in-the-amazon-wildlife references http://ecommerce.natopia.com/natopia/core/check-availability-content not check-availability2..

If there is an anchor link from the luxury page to check-availability page, leave it as is. You want a user to get a full html page if they access the page directly.

let me know if this is unclear.

cheers,

Collapse
Posted by Iuri Sampaio on
Benjamin,

Clear as cristal.
Furthermore, 404 error stoped after I've changed references within luxury-eco-lodge-in-the-amazon-wildlife to check-availability-content.

And that takes us to the begining of the discussion.

Which means, if I set whatever locale (en_US,es_ES,pt_BR), available at page luxury-eco-lodge-in-the-amazon-wildlife, request check-avalability-content?locale='es_ES', it will always be set with default value (en_US).

And I did set locale properly within check-availability-content.

# Select Idiom
switch $locale {
pt {
set locale1 "pt_BR"
}
es {
set locale1 "es_ES"
}
en {
set locale1 "en_US"
}
default {
set locale1 "en_US"
}
}

lang::user::set_locale $locale1

I believe that happens because we have no wrappings (HTML,HEAD) on OACS side then check-availability-content does not switch locale.

Collapse
Posted by Iuri Sampaio on
Benjamin,

Although It does work when accessed directly as you indicated, It doesn't work when accessed through a different website. I don't know if this issue's DNS related, for instance, when included within retreats-detail-right.ctp it doesn't not switches locale accordingly.

http://dev.natopia.com/Retreats/details/rustic-bungalow-retreat-near-trancoso?LanguageName=pt&confRed=&x=8&y=5

Here it's how check-availability-content page on OACS side has been called on php side.

echo file_get_contents('http://ecommerce.natopia.com/natopia/core/check-availability-content?locale='.$locale); ?>

where locale is pt_BR, en_US or es_ES.

Best wishes

Collapse
Posted by Benjamin Brink on
Hi Iuri,

The symptoms indicate that any remaining issues are on the client side, such as javascript.

All I can suggest is a careful audit of the code; You will likely find the source of any remaining issues. Add lots of logging of values so you can check variable values at different points to identify when/where issues begin.

Especially review the code and http transactions that are related to the problem. I cannot follow the javascript and other actions on this page due to time constraints at the moment. Also, my php experience is limited, so I am not much help there.

However, I saw this snip in the content:

..confRed=&x=8&y=5LanguageName=pt&..

Notice that there is no ampersand "&" between the 5 and LanguageName. I'm guessing all remaining issues are typos like this. I have my own I'm dealing with right now 😉

best wishes

Collapse
Posted by Gustaf Neumann on
One possibility is that the locale in the non-javascript case works as expected due to the preferred language settings in the browser. Maybe the according request header field (accept-language) is not set by the javascript code. Try to set Accept-Language (see section 14.4. in [1]) to the desired language in the javascript code and see if you can influence this way the current locale setting in OpenACS.

[1] http://www.ietf.org/rfc/rfc2616.txt

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