PDA

View Full Version : Switching the forum language by using flags [3.5]


Bellinis
09-08-2005, 03:34 PM
On my board we use two official languages. Registered users can change their preferred language through the CP and guests can use the language drop-down menu on the bottom of the page.

Since the drop-down menu isn't very guest-friendly, I would like to add two (or more) language flags somewhere on my page (probably in the menu). Does such hack already excist ? (@ vbulletin.com they told me a hack probably already excists here, but I couldn't find it :disappointed: )
Can anyone point me in the right direction?

Thanks a lot!

Marco van Herwaarden
09-08-2005, 08:54 PM
Can't remember seeing one.

Bellinis
10-01-2005, 10:05 PM
It's been some time ago since I did my posting above....

I think it can't be too difficult to replace the drop-down-language-selection-box with a few country flags somewhere on the forum, only I can not do it :(

Anyone willing to help me out on this one ?

Thanks! :rolleyes:

derfelix
03-21-2006, 05:02 AM
well I was looking for the same solution...
What i did
i placed a flag on the page and

linked it with the following code:<a href="javascript:switch_lang(1);"><img src="images/flag_english.gif" border=0 /></a>


in switch_lang(1) the 1 is your language id corresponding to the language..
you have to change it for the language corresponding to the flag !!!!!

then open forum/clientscript/vbulletin_global.js
in there find:function switch_id(selectobj, type)
and ABOVE add:function switch_lang(language)
{
var id = language;

if (id == '')
{
return;
}

var url = new String(window.location);
var fragment = new String('');

// get rid of fragment
url = url.split('#');

// deal with the fragment first
if (url[1])
{
fragment = '#' + url[1];
}

// deal with the main url
url = url[0];

// remove id=x& from main bit
if (url.indexOf('langid=') != -1 && is_regexp)
{
re = new RegExp("langid=\\d+&?");
url = url.replace(re, '');
}

// add the ? to the url if needed
if (url.indexOf('?') == -1)
{
url += '?';
}
else
{
// make sure that we have a valid character to join our id bit
lastchar = url.substr(url.length - 1);
if (lastchar != '&' && lastchar != '?')
{
url += '&';
}
}

window.location = url + 'langid=' + id + fragment;
}
I hope that helps

Felix

Ramsesx
03-21-2006, 07:09 AM
@ Felix, I only made a link to http://www.mysite.de/index.php?langid=3
What is the advantage to make it with javascript?

derfelix
03-21-2006, 04:24 PM
the advantage is.. that you stay on the page were you were..

example:
you are on https://vborg.vbsupport.ru/showthread.php?p=930702

and you have the flags in the header on every page...

you will after clickin the flag be on:
https://vborg.vbsupport.ru/showthread.php?p=930702&langid=4

with the hard linked method you will be back on the index.php
thats the difference... but in principle both methods work

Felix

Bellinis
03-21-2006, 05:01 PM
Thank you so much derfelix!
I didn't expect a reply anymore, 6 months after I asked my question... hehe :D

Those subscriptions do work fine ;)

Ghostt
03-31-2011, 08:14 PM
can this code also be added as plugin?
seems not to work...