Automatic language detection

Looking for an Extension? Have an Extension request? Post your request here for help. (Note: This forum is community supported; while there is an Extensions Development Team, said team does not dedicate itself to handling requests in this forum)
Suggested Hosts
Post Reply
stevenospam
Registered User
Posts: 84
Joined: Thu Dec 15, 2011 2:02 am

Automatic language detection

Post by stevenospam »

It's been a LONG time since I've worked with the PHPBB3 software but, in the process of upgrading, I've discovered that I had the MOD to detect the preferred language from the browser settings installed. The MOD is not available in 3.2 and I'm wondering if there is a 3.2 enhancement that allows for automatic language detection. I realize the corresponding language pack would have to be installed.
Last edited by JimA on Thu Mar 09, 2017 5:22 pm, edited 1 time in total.
Reason: Moved from 3.2 Translations to Extensions Requests
User avatar
MikovChain
Registered User
Posts: 137
Joined: Tue Aug 29, 2006 9:19 am

Re: Automatic language detection

Post by MikovChain »

You need to edit phpbb/ucp.php
Find

Code: Select all

			if ($lang_override)
			{
				$use_lang = basename($lang_override);
				$user_lang_name = (file_exists($this->lang_path . $use_lang . "/common.$phpEx")) ? $use_lang : basename($config['default_lang']);
				$this->data['user_lang'] = $user_lang_name;
			}
			else
			{
				$user_lang_name = basename($config['default_lang']);
			}
Add the auto detection code after

Code: Select all

$user_lang_name = basename($config['default_lang']);
e.g. on my site, I use this

Code: Select all

            if ($lang_override)
            {
                $use_lang = basename($lang_override);
                $user_lang_name = (file_exists($this->lang_path . $use_lang . "/common.$phpEx")) ? $use_lang : basename($config['default_lang']);
                $this->data['user_lang'] = $user_lang_name;
            }
            else
            {
                $user_lang_name = basename($config['default_lang']);

                if ($request->header('Accept-Language'))
                {
                    $accept_lang_header_ary = explode(',', $request->header('Accept-Language'));

                    foreach ($accept_lang_header_ary as $accept_lang_header)
                    {
                        $accept_lang_ary = explode(';', $accept_lang_header);
                        $accept_lang = $accept_lang_ary[0];
                        // Because we know which languages we have, so just hard code it
                        if ($accept_lang == 'zh' || $accept_lang == 'zh-CN' || $accept_lang == 'zh-SG') {
                            $accept_lang = 'zh_cmn_hans';
                        } elseif (strpos($accept_lang, 'zh') === 0) {
                            $accept_lang = 'zh_cmn_hant';
                        } elseif (strpos($accept_lang, 'en') === 0) {
                            $accept_lang = 'en';
                        }
                        if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
                        {
                            $user_lang_name = $config['default_lang'] = $accept_lang;
                            break;
                        }
                    }
                }
            }
User avatar
jackennils
Registered User
Posts: 229
Joined: Mon Jun 01, 2009 7:48 pm

Re: Automatic language detection

Post by jackennils »

Shouldn't it be sufficient that users choose their language when registering?
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Automatic language detection

Post by david63 »

jackennils wrote: Tue Nov 27, 2018 2:59 pm Shouldn't it be sufficient that users choose their language when registering?
Probably but I suspect that the OP wants to present visitors to the board with their own language showing.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
MikovChain
Registered User
Posts: 137
Joined: Tue Aug 29, 2006 9:19 am

Re: Automatic language detection

Post by MikovChain »

In my case it is not for human beings but for the robots. The robots from some search engines only crawl the pages of specific language. If I don't make it auto detect the visitor's language, the robot may just turn away at the first page.
Post Reply

Return to “Extension Requests”