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

Collapse
Posted by Iuri Sampaio on
Yes,

Requests come from http://www.natopia.com/Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife

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

Why? I haven't restricted anything on OACS side, the page is open for public access

Collapse
Posted by Benjamin Brink on

Hi Uri,

Could the problem be with content in the default-master (or blank-master)?

ecommerce.natopia.com's page returns this tag:

<html lang="en">

To test the two pages, I used these http requests and telnet from bash shell:

$ telnet ecommerce.natopia.com 80
GET /natopia/check-availability HTTP/1.1
Referer: http://www.natopia.com/Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife
Host: ecommerce.natopia.com
Accept-Language: es_ES
Accept-Charset: utf-8
User-Agent: telnet-test/0.9

and

$ telnet www.natopia.com 80
GET /Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife
Host: www.natopia.com
Accept-Language: es_ES
Accept-Charset: utf-8
User-Agent: telnet-test/0.9

My browser shows Spanish content for ecommerce.natopia.com even though it's default is English.

There's a lot of content on these two urls that make it somewhat difficult to identify a root cause. If the problem persists, consider creating test pages in same environments with as few extras as possible.

cheers,

Collapse
Posted by Iuri Sampaio on
By your ideas above I believe I found the reason for i18n isn't changing.

"www.natopia.com/Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife" has its html block tag, as well as ecommerce.natopia.com/natopia/check-availability has its own html block tag.

Thus, html final code is something like

html xmlns="http://www.w3.org/1999/xhtml";
...
html lang="en"
...
/html

/html

I believe that is why neither i18n messages don't get changed to spanish.

Another evidence is even though I've added a javascript call on openacs side within html header block, javascript chunk doesn't work.

I wonder If I remove master src="blank-master" things would work out. However I know it ins't recommended to have those kind of integration among separated websites/environments.

Collapse
Posted by Iuri Sampaio on
How would I have such integration among websites?

Any ideas?

Collapse
Posted by Benjamin Brink on

Hi Iuri,

If you want to use content from one website's page in another, but don't want to include the master, you can expose the page content on its own url, much like an adp include in package-key/lib

As I understand your example, you want the contents of page: http://ecommerce.natopia.com/natopia/check-availability to be included in: http://www.natopia.com/Retreats/details/luxury-eco-lodge-in-the-amazon-wildlife

Here is one way to do this:

1. create a "check-availability-content" page as a copy of "check-availability" page, but without the adp referring to master template (a variation of <master> tag).

2. create a "check-availability2" page that is a copy of "check-availability".

3. Replace the content in check-availability2 page with an include in the adp part that looks something like <include src="/packages/ecommerce/www/check-availability-content">

Test the results of check-availability2 versus check-availability-content. Refer to check-availability-content page from the external website, and check-availability2 when the page is serving content directly.

When you are satisfied it works as intended, replace check-availability with the check-availaility2 version.

I've done this before at various times. Let me know if it does not work for you.

best wishes,
Benjamin

Collapse
Posted by Iuri Sampaio on
Benjamin,

I followed your steps and I got into something surprisingly worst. Check-availability-content is gone. Pop-up shows only half way through, meaning the chunk located on OACS's side isn't included as expected.

If you open html page source on your browser, http://www.natopia.com/experiences/details/luxury-eco-lodge-in-the-amazon-wildlife, you'll witness only comments and nothing within it,


-- BEGIN INCLUDE CHECK-AVAILABLITY JAVASCRIPT SOURCE
-- Author Iuri Sampaio (mailto:iuri.sampaio@iurix.com)
-- Date 2014-06-21
-- http://dev.natopia.com/app/View/Elements/experience/retreats-detail-right.ctp line 1445
--



-- END INCLUDE CHECK-AVAILABLITY JAVASCRIPT SOURCE --

Plus, there's no errors within log/error.log except for a 404.

[21/Jun/2014:17:09:16][8324.7ffa1449a700][-conn:natopia:6] Error: return: failed to redirect '404': exceeded recursion limit of 3

My guess: there's something blocking access even before include call. Otherwise html code would be inside of the comment block. I added within check-availability2.adp .

Here it's check-availability2.adp

!--
BEGIN INCLUDE CHECK-AVAILABLITY OACS SIDE
-- Author Iuri Sampaio (mailto:iuri.sampaio@iurix.com)
-- Date 2014-06-21
-- /packages/natopia-core/check-avilability.adp
--

master src="/www/blank-master"
include src="/packages/natopia-core/www/check-availability-content"

You might want to open http://ecommerce.natopia.com/natopia/core/check-availability2

Page's served properly, meaning there's nothing wrongly coded on OACS side.

However I can't confirm because I have no errors within "error.log" on both sides. Neither OACS nor Apache.

Last but not least, wouldn't be better if check-availability-content.adp was within the directory /packages/package-name/lib ?

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