2

So there's this plugin for wordpress, Transposh: http://transposh.org/ its basically a translation engine. I have this site i'm owrking on where when a user visits the site the site checks for Transposh's Language preference cookie like this:

<?php if( isset( $_COOKIE['TR_LNG'] ) ) {} else { ?>

and if the cookie (called TR_LNG) is not found it proceeds to show a language selection dialogue, that has links to both English and French versions of the site. The problem is transposh's own widget sets the default language like this: the suer selects language on widget. Widget loads required language page and displays a link below the widget that says Set this language as default. The link looks like this:

<a id="tr_setdeflang" class="tr_setdeflang" onclick="return false;" href="http://sarvatma.org/wp-admin/admin-ajax.php?action=tp_cookie_bck">Set this lang....</a>

what I need to happen is, when a user clicks a language in the language preference dialogue that looks like this:

<a href="http://www.sarvatma.org/en/">In English</a>

I need it to also set the language, English in the above example as the default. That's the best I can explain my situation, if you need anymore info just let me know.

Atom Vayalinkal
  • 2,642
  • 7
  • 29
  • 37

1 Answers1

2

If I understand, you just need to bind the setting of a cookie to the clicking of the link?

If so, you need to add an ID to your <a>:

<a href="http://www.sarvatma.org/en/" id="mylink">In English</a>

Then bind some cookie-setting code to the click event:

(Using jQuery)

$("a#mylink").bind("click", function() {
    $.cookie("TR_LNG", "English");
});
ZachB
  • 13,051
  • 4
  • 61
  • 89
  • 1
    but would the cookie be set before the page is loaded? – Atom Vayalinkal Aug 20 '12 at 01:21
  • Which page? That code will set the cookie when "In English" is clicked. If you want to set the cookie when the page is loaded, use `$(document).ready(function() { $.cookie("TR_LNG", "English"); });`. I'm not really clear what you're trying to do. – ZachB Aug 20 '12 at 01:23
  • if the cookie is set immediately this should work, as in if it is set before the href of the link loads, i'll try it out as soon as i can and let you know if it works – Atom Vayalinkal Aug 20 '12 at 01:31
  • that didnt work it laoded the page but no cookie was set. check the page here: sarvatma.org – Atom Vayalinkal Aug 20 '12 at 02:01
  • 1
    You didn't include the jQuery.cookie plugin (https://github.com/carhartl/jquery-cookie). To do it without jQuery.cookie, replace the `$.cookie` bit with `document.cookie="TR_LNG=English;path=/;"`. – ZachB Aug 20 '12 at 02:12
  • THANK YOU! It worked! Do i just add the expiry date the usual way? or is there anything else i need to know? – Atom Vayalinkal Aug 20 '12 at 02:20
  • Cool. The usual way... `"TR_LNG=English;path=/;expires="+...`. – ZachB Aug 20 '12 at 02:22