Resource icon

Auto Language Switcher 1.1

No permission to download

Akinak

Well-known 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!
 
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);
 
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.
 
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
 
  • Like
Reactions: sbj
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

Thanks.
Do I need to do that code from above, too or just this?
 
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
 
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

Thank You, Alex.
I am add this fix to resource archive.
 
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!
 
I get an error when installing it...

default_value is not a valid array (autoLangSwitchOption)

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:
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:
Back
Top Bottom