SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Change language first time?
-
Dec 12, 2009, 02:57 #1
- Join Date
- Dec 2005
- Posts
- 964
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Change language first time?
I'm making a multilanguage site, but I am having some trouble when changing language?
When a user click on a flag he has to refresh once before the language changes... How do I fix this?
PHP Code:$lang = urlencode($_GET['lang']);
setcookie("lang",$lang,time()-60*60*24*365,"/",".mypage.com",0);
setcookie("lang",$lang,time()+60*60*24*365,"/",".mypage.com",0);
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$fullUrl = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo '<a href="'.$fullUrl.'&lang=da"><img src="images/flags/flags_16x16/213.png" title="Danish" style="padding:1px;"></a>';
echo '<a href="'.$fullUrl.'&lang=en"><img src="images/flags/flags_16x16/225.png" title="English" style="padding:1px;"></a>';
-
Dec 12, 2009, 05:32 #2
- Join Date
- Oct 2009
- Posts
- 1,852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There is no code provided, that actually changes language, so we have to guess.
I bet it depends on the cookie, so, because cookie contains previuos language, user have to refresh the page. Make it to use GET param too.
-
Dec 12, 2009, 05:45 #3
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
Optionally, once the cookie has been set you can redirect back to the same page, which performs that second load that you seem to require.
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Dec 12, 2009, 07:09 #4
- Join Date
- Dec 2005
- Posts
- 964
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Dec 12, 2009, 07:12 #5
- Join Date
- Oct 2009
- Posts
- 1,852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
not in this.
not in the code that builds link
in the code that choose language based on cookie
-
Dec 12, 2009, 07:41 #6
- Join Date
- Dec 2005
- Posts
- 964
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks