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: 44
Joined: Thu Dec 15, 2011 2:02 am

Automatic language detection

Post by stevenospam » Thu Mar 09, 2017 4:46 pm

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 » Tue Nov 27, 2018 2:57 am

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: 194
Joined: Mon Jun 01, 2009 7:48 pm

Re: Automatic language detection

Post by jackennils » Tue Nov 27, 2018 2:59 pm

Shouldn't it be sufficient that users choose their language when registering?

User avatar
david63
Jr. Extension Validator
Posts: 15087
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Automatic language detection

Post by david63 » Tue Nov 27, 2018 3:25 pm

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!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
MikovChain
Registered User
Posts: 137
Joined: Tue Aug 29, 2006 9:19 am

Re: Automatic language detection

Post by MikovChain » Thu Nov 29, 2018 6:56 am

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”

Who is online

Users browsing this forum: No registered users and 13 guests