Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2009-07-26 21:57:15

mungy
Member
Registered: 2006-03-12
Posts: 22

Re: Bilingual website

thank you Pat64. I’ve been too busy with housework to try anything today. hopefully I’ll get it up and running tomorrow with the aid of some coffee.

thanks everyone who has helped me so far. if you are ever in north wales, i owe you all a beer :D

Offline

#17 2009-07-27 11:07:49

mungy
Member
Registered: 2006-03-12
Posts: 22

Re: Bilingual website

I’m having problems with Patrick’s solution. How can I load the selected language using the <txp:variable> tag?

also.

<txp:if_section name=""><txp:php>if($_SESSION['language'] == 'fr') { header ('Location: '.hu.'fr'); } else { header ('Location: '.hu.'en'); }</txp:php>

is that complete or is there something missing.

to be honest, I’m confused now. :D

Offline

#18 2009-07-28 05:40:44

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,680
GitHub Twitter

Re: Bilingual website

@mungy

Look at txptips.com and specialy the latest Robert’s (Core Developer) tutorial . It’s great.

Now, you can create a form named “browser_language_detection” (type “misc”) and put this in it:

<txp:php>
variable(array('name' =>'accept-language', 'value' => 'en'));
$al = @$_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (preg_match('/(.*?)[,;-]/', $al, $a)) {
    variable (
        array (
              'name' =>'accept-language', 
              'value' => $a[1]
        )
    );
}
</txp:php>

You’ve got now a <txp:variable named accept-language its value has the client’s browser language. It’s pretty usefull.

Call your browser_language_detection form at the very begining of your main page template (“default”):

<txp:output_form form="browser_language_detection" /><!DOCTYPE (...)

At the place of your choice add some kind of select lang list for your visitors:

<ul><li><a href="/en" title="English version">English</a></li><li><a href="/" title="Version française">Français</a></li></ul>

Create a section named “en” for your English home page. Add all needed <txp:article tags to grab your english articles only.

In your “default” template, add this line just before your final </head> html tag:

<txp:if_section name=""><txp:if_variable name="accept_language" value="en"><txp:php>
header ('Location: '.hu.'en');
</txp:php></txp:if_variable></txp:if_section>

In the code above, you test the variable value. If it contains “en” you redirect your visitors to the “en” section. Otherwise, you stay in the “default” one.

It’s the idea. Adapt it for you purpose. Remember you need to create separate sections for the specific parts of your site for each languages (only 2. See my previous post). Use the “default” template ONLY for the home page otherwise you could create an infinite redirection failure .

It is a solution. Perhaps someone could help you with another one. Ask to this forum. There are plainty of clever guys with lot of ideas here.

Best regards,

P.S. My latest advice. Did you think about your website organisation? I think it’s the FIRST thing to do. All your future decisions will depend of this very first step.

Last edited by Pat64 (2009-07-28 06:07:15)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#19 2009-07-28 16:22:47

mungy
Member
Registered: 2006-03-12
Posts: 22

Re: Bilingual website

thank you, once again patrick for spending time to help me understand.

Offline

#20 2009-07-30 19:35:25

mungy
Member
Registered: 2006-03-12
Posts: 22

Re: Bilingual website

Thanks guys for all your help.

In the end I have opted for a “very poor man’s” solution.

I am doing this using :-

<txp:section name="en">English</txp:section> - <txp:section name="cy">Cymraeg</txp:section>

to allow the user to select the language. For the time being I’m not worried about getting the browsers language, that was confusing me :D

I’m using 2 pages one containing the welsh and the other containing the english.

Once again, thank you for the help.

Pints all round!

Offline

#21 2010-01-23 14:42:10

ilyuha
Member
Registered: 2008-02-14
Posts: 10

Re: Bilingual website

Website in two languages. Determine the value of $HTTP_ACCEPT_LANGUAGE, and, depending on its value, given the content of one of the languages. How to assign a button on javascript, which will change the value of $HTTP_ACCEPT_LANGUAGE in browser? How to switch languages? With AJAX, cookies? Thanks! (sorry my English :)

form accept-language:

<txp:php> 
variable(array('name' =>'accept-language', 'value' => 'ru')); 
$al = @$_SERVER['HTTP_ACCEPT_LANGUAGE']; 
if (preg_match('/(.*?)[,;-]/', $al, $a)) { 
    variable ( 
        array ( 
              'name' =>'accept-language',  
              'value' => $a[1] 
        ) 
    ); 
} 
</txp:php>
page default:
<txp:output_form form="accept-language" /> 
<txp:if_variable name="accept-language" value="ru"> 
    _russian text_
<txp:else /> 
    _non russian text_
</txp:if_variable>

Offline

Board footer

Powered by FluxBB