Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Multilingual content issues fixed, method explained

I wrote a small document about this a while long ago after the first implementations ( I just updated with CP´s as well, thank you Riz ).

To not confuse anyone, the method we have selected for multilingual content is what I call instanced.
This means that we do a new id for each language rather than an array for a multitude of languages with a multitude of either fields or an extra database that stores the content. The more I think of it, the more I still want it to stay like this. The method is set for this version anyway.

I have put a lot of focus to solve this from just working occationally to fully stable.
Until a few patches ago we used to have a lot of random crashes when switching language between language content and in general when dealing with languages in subfolder levels, many issets etc etc..

This problem have had many layers to it.

My first and most important issue was to solve direct linking to a non system default language content instance.
For example,
News item 11 are in Swedish, someone links this, the system Language is English, when you visited the link, our system would fall back to News index since it could not find News item 11 under English.
Sure, we can say that an array would solve it, but in fact it would only solve it partially. It would solve the ID of the news item but I would still need to manually change the language unless I link the ?lang=XXX switch.
Unless we use a permalinks with like news/LANG/xxxxxx however that are, to me not so pretty either when the new perma link system can root everything like /MY-fancy-news-item ( regardless of Language ). Not to mention that it looks really silly for people with no permalink options.

Naturally, if a webmaster would like to keep any section non instanced they can simply turn the MLT Tables off in the Administration for each section.
Admin Dashboard > Settings > Language Settings > Tables with multilanguage content.

The solution I have is the hub that I have integrated.
The hub will detect and redirects directly to the correct language if a match is found.
We can also optimise this to a integrated version that acts directly with in the requested content´s query's further on.

// This part still need some tinkering, seems to only be an issue with subdirs Involved..
When it came to the linking issues depending on directory, issets etc it was depending on
FUSION_QUERY, we need that to repeat position when initiating a language switch.
Even if it is instanced we need to remain in the correct area, such as forum, articles etc.
When we do it like that we also often echoed the basepath twice, crashing the whole function with double base paths.

I simply patched that with a replacement of nothing from the system´s site path, it seems to have taken care of these issues as well.


$link_prefix = str_replace($settings['site_path'], "", $link_prefix);
The language detection have been refined,

We save us from directs and make the linking seamless.

This way it does not matter if it is a SEO page or a non-SEO page, it just work and we keep the individual language part´s instanced.

// Forum threads
elseif (preg_match('/viewthread.php/i', $_SERVER['PHP_SELF']) || preg_match('|/thread/([0-9]+)/|', $_SERVER['REQUEST_URI'], $matches) && multilang_table("FO")) {
   if (isset($_GET['thread_id']) && isnum($_GET['thread_id']) || $matches['1'] > 0) {
      $data = dbarray(dbquery("SELECT f.forum_id,f.forum_language, t.thread_id
                        FROM ".DB_FORUMS." f
                        LEFT JOIN ".DB_FORUM_THREADS." t ON f.forum_id = t.forum_id
                        WHERE t.thread_id='".(isset($_GET['thread_id']) ? $_GET['thread_id'] : $matches['1'])."'
                        GROUP BY t.thread_id"));
      if ($data['forum_language']." != ".LANGUAGE) {
         echo set_language($data['forum_language']);

Updated function in order to void a re-load to to cookies we enable database handling for guest language sessions.


// Set the requested language
function set_language($lang) {
global $userdata;
   if (iMEMBER) {
      dbquery("UPDATE ".DB_USERS." SET user_language='".$lang."' WHERE user_id='".$userdata['user_id']."'");
      $userdata['user_language'] = $lang;
   } else {
      $rows = dbrows(dbquery("SELECT user_language FROM ".DB_LANGUAGE_SESSIONS." WHERE user_ip='".USER_IP."'"));
   if ($rows != 0) {
      dbquery("UPDATE ".DB_LANGUAGE_SESSIONS." SET user_language='".$lang."', user_datestamp='".time()."' WHERE user_ip='".USER_IP."'");
   } else {
      dbquery("INSERT INTO ".DB_LANGUAGE_SESSIONS." (user_ip, user_language, user_datestamp) VALUES ('".USER_IP."', '".$lang."', '".time()."');");
// Sanitize guest sessions occasionally
   dbquery("DELETE FROM ".DB_LANGUAGE_SESSIONS." WHERE user_datestamp<'".(time()-(86400 * 60))."'");

Thread Information
2 posts
1,131 times
Last Post
Last updated on 4 years ago
You can view all discussion threads in this forum.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.