Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
detect language and...
Is there a way I can detect the language and echo a particular text?
This is what I am trying to acheive
if english <span>Welcome to the site. Please visit the <a href="#">about page</a></span>
else if greek: <span lang="el">Καλώς ήρθατε στην ιστοσελίδα. Παρακαλούμε επισκεφθείτε <a href="#">a greek about page</a></span>
else if german: <span lang="de">Willkommen auf der Webseite. Bitte besuchen Sie <a href="#">a german about page</a></span>
etc...
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#2 2010-06-16 07:25:53
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: detect language and...
I assume you don’t want to use MLP? Have a look at Robert’s article.
Offline
Re: detect language and...
Els wrote:
I assume you don’t want to use MLP? Have a look at Robert’s article.
That’s exactly what I was looking for! THanks Els.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: detect language and...
In Robert’s article:
<txp:php>
variable(array('name' =>'accept-language', 'value' => 'de'));
$al = serverSet('HTTP_ACCEPT_LANGUAGE');
if (preg_match('/(.*?)[,;-]/', $al, $a)) {
variable (
array (
'name' =>'accept-language',
'value' => $a[1]
)
);
}
</txp:php>
what happens if one needs more than one language?
would the code be
<txp:php>
variable(array('name' =>'accept-language', 'value' => 'de,el,fr'));
$al = serverSet('HTTP_ACCEPT_LANGUAGE');
if (preg_match('/(.*?)[,;-]/', $al, $a)) {
variable (
array (
'name' =>'accept-language',
'value' => $a[1]
)
);
}
</txp:php>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: detect language and...
No. variable(array('name' =>'accept-language', 'value' => 'de'));
establishes the default language (de
in this case) if for whatever reason we cannot determine the client’s language preferences (e.g. if some search engine spider visits).
The next step pulls a client’s language preferences into the accept-language
variable. So there you have it at your disposal for any imaginable set of <txp:if_variable>
branches:
<txp:if_variable name="accept-language" value="de">
German content goes here...
</txp:if_variable>
<txp:if_variable name="accept-language" value="en">
English content goes here...
</txp:if_variable>
<txp:if_variable name="accept-language" value="fr">
French content goes here...
</txp:if_variable>
<txp:if_variable name="accept-language" value="it">
Italian content goes here...
</txp:if_variable>
Offline
Re: detect language and...
Got it! Beautifully simple!
thanks soooo much
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Pages: 1