SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    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.'&amp;lang=da"><img src="images/flags/flags_16x16/213.png" title="Danish" style="padding:1px;"></a>';
    echo 
    '<a href="'.$fullUrl.'&amp;lang=en"><img src="images/flags/flags_16x16/225.png" title="English" style="padding:1px;"></a>'

  2. #2
    Non-Member
    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.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 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

  4. #4
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    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.
    How should I user the GET in this?
    PHP Code:
    echo '<a href="'.$fullUrl.'&amp;lang=da"><img src="images/flags/flags_16x16/213.png" title="Danish" style="padding:1px;"></a>'

  5. #5
    Non-Member
    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

  6. #6
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    not in this.
    not in the code that builds link
    in the code that choose language based on cookie
    Ahhh... sorry... Didn't read it good enough...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •