Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2024-10-12 15:17:57

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Re: [SOLVED] oui_cookie and site/page languages

How about not deleting the language cookie at all, but setting for example en as its default value? Something like this:

<txp:variable name="lang" value='<txp:php> echo gps("lang"); </txp:php>' />
<txp:if_variable name="lang" value="el" match="exact">
<txp:oui_cookie name="lang" duration="1 year" value="el" />
<txp:else />
<txp:oui_cookie name="lang" duration="1 year" value="en" />
</txp:if_variable>
<txp:oui_if_cookie name="lang" value="el">
<txp:variable name="title" value="Τίτλος σελίδας" />
<txp:variable name="description" value="Περιγραφή σελίδας..." />
<txp:else />
<txp:variable name="title" value="Page title" />
<txp:variable name="description" value="Page description..." />
</txp:oui_if_cookie>
<p><a href="?lang=el">GR</a></p>
<p><a href="?lang=en">EN</a></p>

Offline

#14 2024-10-12 15:26:38

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

kuopassa wrote #338002:

How about not deleting the language cookie at all, but setting for example en as its default value? Something like this:

<txp:variable name="lang" value='<txp:php> echo gps("lang"); </txp:php>' />...

<txp:if_variable name="lang" value="el" match="exact">...

<txp:oui_if_cookie name="lang" value="el">...

<p><a href="?lang=el">GR</a></p>...

Thanks so much for the suggestion. Would this mean that all urls will have to be appended with ?lang=el or ?lang=en? What happens to pages that have just the txp:article_url?

Also wouldn’t this confuse the browser as to which language to load when visiting txp:article_url if both cookies are set?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#15 2024-10-12 15:45:51

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Re: [SOLVED] oui_cookie and site/page languages

?lang=el or ?lang=en is used only to change language by storing the language code in a cookie. :-) So you don’t need to append that stuff to page URLs.

Offline

#16 2024-10-12 16:03:37

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

Thanks so much. Will test.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#17 2024-10-12 16:21:18

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

It works! Thanks so much!

see it in action.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#18 2024-10-12 16:31:10

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Re: [SOLVED] oui_cookie and site/page languages

That’s great! :-)

Offline

#19 2024-10-12 16:59:10

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: [SOLVED] oui_cookie and site/page languages

Here is how it looks in an article:

notextile. <txp:variable name="lang" value='<txp:php> echo gps("lang"); </txp:php>' />
<txp:if_variable name="lang" value="el" match="exact">
<txp:oui_cookie name="lang" duration="1 day" value="el" />
<div lang="el">
p>. <a lang="en" rel="nofollow noindex noodp noydir noarchive nocache" href="?lang=en">Read the original English text.</a>

Λορεμ ιπσθμ δολορ σιτ αμετ, αθι εα πθρτο προμπτα δελεγτθς γθ.
notextile. </div>
<txp:else />
<txp:oui_cookie name="lang" duration="1 day" value="en" />
p>. <a rel= "nofollow noindex noodp noydir noarchive nocache" href="?lang=el">Διαβάστε μετάφραση του άρθρου στα Ελληνικά.</a>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
notextile. </txp:if_variable>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#20 2024-10-12 17:09:53

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,445
Website GitHub

Re: [SOLVED] oui_cookie and site/page languages

One cookie instead of two, woot. Nice approach, kuopassa.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB