Hello, I would like to know if you plan including cookie suppor for the i18n module, this way when you select a language the website remembers your selection in your next visit.

This would be important for anonymous users, for example in corporate or information sites where not all users need to register.

I know the browser language detection is important but sometimes a user has a browser with one language but prefers using another language for visiting a site and changing it everytime could be annoying.

If there are not plans to make this addition, yet, would it be possible for me to create a new module to do this or would you better suggest modifying i18n module itself?, if so, which function (or functions) should I look at?

Thanks!

Comments

steffen’s picture

* Setting cookie for consistent language, overriding browser detection for anonymous users *

I know it's not much, but I'll throw in EUR 50,- to anyone's PayPal account, if they integrate this within a week (by Wednesday 28 September 2005). Need to be working with Drupal 4.6. Cookie should be set when clicking on the flag. If the user is logged in, this should also change default language for account.

Steffen

jax’s picture

Here, this does exactly what you want...

--- i18n.module.orig    2005-09-22 12:40:58.000000000 +0200
+++ i18n.module 2005-09-22 12:40:18.000000000 +0200
@@ -241,6 +241,11 @@
     return $i18n_lang;
   }

+  if (isset($_COOKIE['i18n_lang'])) {
+    $i18n_lang = $_COOKIE['i18n_lang'];
+    return $i18n_lang;
+  }
+
   $languages = i18n_supported_languages();

   if ($i18n_langpath && array_key_exists($i18n_langpath,$languages)) {
@@ -255,7 +260,7 @@
   else {
     $i18n_lang=key($languages);
   }
-
+  setcookie('i18n_lang', $i18n_lang, time() + 604800); // expire in 1 week
   return $i18n_lang;
 }

jax’s picture

actually it doesn't do what you want hold on...

jax’s picture

much better

--- i18n.module.orig    2005-09-22 12:40:58.000000000 +0200
+++ i18n.module 2005-09-22 12:54:09.000000000 +0200
@@ -246,6 +246,9 @@
   if ($i18n_langpath && array_key_exists($i18n_langpath,$languages)) {
     $i18n_lang = $i18n_langpath;
   }
+  elseif (isset($_COOKIE['i18n_lang'])) {
+    $i18n_lang = $_COOKIE['i18n_lang'];
+  }
   elseif ($user->uid && $user->language && array_key_exists($user->language,$languages)) {
     $i18n_lang = $user->language;
   }
@@ -256,6 +259,7 @@
     $i18n_lang=key($languages);
   }

+  setcookie('i18n_lang', $i18n_lang, time() + 604800); // expire in 1 week
   return $i18n_lang;
 }

Enjoy!

steffen’s picture

Thanks! I'll test it straight away.

steffen’s picture

Working excellent :)

jose reyero’s picture

Status: Active » Closed (won't fix)

Well, this will work. For whom it may interest the patch is here.

For further discussion on these issues, please see: http://www.developmentseed.org/blog/internationalization/otherfeatures/l...

In other words, no plans to implement this into the module.

And a BIG warning. This may cause security problems. Please contact me if you want more detail. Not willing to give away too many clues here....

xalexas’s picture

can't find that article on that address. It look like it does not exist anymore.