Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
Re: [SOLVED] oui_cookie and site/page languages
It works! Thanks so 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
Offline
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
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
#21 Today 03:52:28
Re: [SOLVED] oui_cookie and site/page languages
I think that I have hit a limitation with this method when wanting to show a translation of a live or sticky article on a section’s front page.
Removing the notextile
parts, this is what I have in the article:
<txp:variable name="lang" value='<txp:php> echo gps("_NeMe_lang"); </txp:php>' />
<txp:if_variable name="lang" value="el" match="exact">
<txp:oui_cookie name="_NeMe_lang" duration="30 minutes" value="el" />
<div lang="el">
<a lang="en" rel="bookmark" hreflang="en" href="https//:site.tld/about/>">Read the original English text.</a>
Ελληνικά
</div>
<txp:else />
<txp::lang_el url="https//:site.tld/about/" />
English
</txp:if_variable>
and this is the lang_el
shortcode.
<aside>
<p style="text-align:right;" class="noprint">
<a rel="nofollow noindex noodp noydir noarchive nocache alternate"
hreflang="el" href="<txp:if_yield name="url"><txp:yield name="url" />
<txp:else />
<txp:permlink />
</txp:if_yield>?_NeMe_lang=el">
<txp:if_yield name="txt"><txp:yield name="txt"/>
<txp:else />
Διαβάστε μετάφραση του άρθρου στα Ελληνικά.
</txp:if_yield>
</a>
</p>
</aside>
<txp:oui_if_cookie name="_NeMe_lang"><txp:oui_cookie name="_NeMe_lang" delete /></txp:oui_if_cookie>
The default english looks fine, the greek translation shows the english text instead. This only happens on the sections front pages and it does not happen in the front pages of categories and the individual articles. As this works everywhere else, I have no Idea what it is that makes it fail in this context.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline