1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto Language Switcher 1.1

change default language to guest depend of browser settings

  1. Akinak

    Akinak Well-Known Member

    Akinak submitted a new resource:

    Auto Language Switcher - change default language to guest depend of browser settings

    Read more about this resource...
     
    Sankisan and Mirovinger like this.
  2. Sankisan

    Sankisan New Member

    Thank you sooo much for this plugin!!

    It works perfekt, but I have got one 'small' problem:
    I have 2 languages, German/English. English is the default language.
    Everything works fine, and if the browser is german, visitors will se the German page - Perfekt!

    BUT
    If a visitor is registering, the registration form and everything is in German, but once he is registered, his language is set to English (default language).

    Any ideas how to fix this? Maybe show the language selection in the registration form would be an solution, or there is another solution to this problem.

    Thanks again for your excellent plugin!
     
  3. Sankisan

    Sankisan New Member

    It's me again, I think I have fixed the problem :)

    I have added the following line to your code, to set the cookie to the dedected language, and now user registration is working fine :)

    I'm not sure if this is the correct fix, but it seems to work fine

    Code:
          $visitor['languageId'] = $key;
          $visitor->setVisitorLanguage($key);
         
           // set cookie added by ALX
           XenForo_Helper_Cookie::setCookie('language_id', $key, 86400 * 365); 
     
    Akinak likes this.
  4. sbj

    sbj Well-Known Member

    When this add-on is activated, unregistered people can not change language.
    It is good that this add-on automatically change the language. But some people will want to change to another language. It is not possible.
     
  5. Sankisan

    Sankisan New Member

    Hello,

    just modify the code in visitor.php to the following
    Code:
                        if (trim($subLang) === $http_lang) {
                            $visitor['languageId'] = $key;
                          
                            if (XenForo_Visitor::getInstance()->get('language_id')== 0){ // checks if language cookie is set (by Sankisan)
                                $visitor->setVisitorLanguage($key);
                                XenForo_Helper_Cookie::setCookie('language_id', $key, 86400 * 365); //Set the language cookie (by Sankisan)
                            }
                            return;
                        }
      
    
    This will auto set the language to browser settings for guests, but let them also change the language.

    hope this helps

    best regards
    Alex
     
    sbj likes this.
  6. sbj

    sbj Well-Known Member

    Thanks.
    Do I need to do that code from above, too or just this?
     
  7. Sankisan

    Sankisan New Member

    Sorry, it's hard to explain:

    the easiest may be you exchange this part of the orignal code:

    Code:
    foreach ($langOpts as $key=>$language) {
                    $lang = explode(',',$language);
                    foreach ($lang as $subLang) {
                        if (trim($subLang) === $http_lang) {
                            $visitor['languageId'] = $key;
                            $visitor->setVisitorLanguage($key);
                             XenForo_Helper_Cookie::setCookie('language_id', $key, 86400 * 365);                  
                            return;
                        }
                    }
                }
    with this modified code

    Code:
           foreach ($langOpts as $key=>$language) {
                    $lang = explode(',',$language);
                    foreach ($lang as $subLang) {
                        if (trim($subLang) === $http_lang) {
                            $visitor['languageId'] = $key;                 
                            if (XenForo_Visitor::getInstance()->get('language_id')== 0){  //check if cookie is set (by Sankisan)
                                $visitor->setVisitorLanguage($key);
                                XenForo_Helper_Cookie::setCookie('language_id', $key, 86400 * 365); //set the language cookie (by Sankisan)
                            }// end Cookie check (by Sankisan)
                            return;
                        }
                    }
                }
    
    
    The other parts of the code keep untouched, so just add 3 lines (the ones followed by // ) :)


    This will add 3 lines to the code fixing these problems :)

    At least it works fine at my page.

    This modification will do the following (for guests only)

    Check if the language cookie has been already set.
    Case 1: Cookie not set: It will set the language to to the browser settings, and stores it into a cookie
    Case 2: Cookie has been already set (by language chooser or because the guest is visiting again), it will do nothing :)

    So only very new guest visitors will get the language of their browswer, once they have a cookie, their language will not autoset anymore, that's why they can still change the language to another language if they are just visitors.

    Let me know if you have any additional qestions.
    It works fine on my page (as far as I have tested), but it is still some kind of guessing, since I'm very new to the xenforo, so I would be glad if any developer could confirm my modifications... thanks

    ...alex
     
    rafass and sbj like this.
  8. Akinak

    Akinak Well-Known Member

    rafass and Mirovinger like this.
  9. Akinak

    Akinak Well-Known Member

    Thank You, Alex.
    I am add this fix to resource archive.
     
  10. rafass

    rafass Well-Known Member

    Awesome and working like a charm, thank you so much Akinak!
     
  11. rafass

    rafass Well-Known Member

    Hello Akinak, there are some way to extend the feature of this addon to recognise and define languages for each node/category?
    I really need this feature. Thanks for your great work!
     
  12. Akinak

    Akinak Well-Known Member

    Hello, Rafass ) I'll think about it, and may be i'll prepeare an update for this addon.
     
    Sparkiller and rafass like this.
  13. rafass

    rafass Well-Known Member

    Awesome Akinak! it would be really great! YOU ROCK!
    Thanks! (y)
     
  14. Wasserlasser

    Wasserlasser Active Member

    I get an error when installing it...

    When I remove this line, installing works.
    But then I can no longer change the language. I have to clear the cookie in order for it to work.

    Thanks

    Wasserlasser
     
    Last edited: Jan 9, 2016
    bluehuge likes this.
  15. CrispinP

    CrispinP Active Member

    Same here, does not work on 1.5.
     
  16. SirWill

    SirWill Member

    Search for a:{1:en} in the xml file and remove it, then you should be able to install it.
     
  17. CrispinP

    CrispinP Active Member

    thanks. Will try that.
     
  18. Robert9

    Robert9 Active Member

    I have set up the addon after deleting the whole line with a:{1:en},
    then i have seen the options to add language-codes.

    Here i would like to say:

    use german for de,ch,at
    use english "for all others"

    Is the solution to setup english as default language for guests and define only

    use german for de, ch, at ?


    ----------------

    Yes, seems to be ok.
     
    Last edited: Sep 19, 2016
  19. ptvinhdtk1

    ptvinhdtk1 Member

    @Akinak Help me! I get an error installing
    Capture.PNG
     
  20. Robru

    Robru Active Member

    ptvinhdtk1 likes this.

Share This Page