Enable Browser Language Detection

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in the Customisations Database.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTICE: This forum is only for the announcement of new releases and/or updates of MODs. Any MOD support should be obtained through the Customisations Database in the support area designated for each MOD.

A direct link to support for each MOD is in the first post of the respective topic.
Daniel_L
Registered User
Posts: 113
Joined: Fri Jan 04, 2008 3:01 pm

Re: Enable Browser Language Detection

Post by Daniel_L »

This is something I was looking for. I already use language detection for my own website and without a lot of knowledge in php I wanted to look how I could merge it so the forum would detect browser language and display accordingly.

I want to know if your mod is safe, what I mean if that for any reason it cannot detect it will default to english.

See my code :

Code: Select all

<?php
	if (!isset($Langue))
	 	{
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
			{
			$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
			$Langue = strtolower(substr(chop($Langue[0]),0,2));
			if ($Langue !== 'fr' && $Langue !== 'en')
				{ 
				$Langue = "en";
				}
			}
		else
			{
      $Langue = "en";
			}
		}
	else
		{
		$Langue="en";
		}

	include $_SERVER["DOCUMENT_ROOT"] . ("/index-$Langue.php");
?>
You see the country is removed and that every condition fallback to "en" if language cannot be detected.

While I was looking to where I could place that code and change the last line so phpBB can use it I think your mod already does all this, right?

Thanks
Successfully running phpBB 3 on an association website since Feb 25th of 2008.
I'm a voluntarily webmaster.
User avatar
Martin Truckenbrodt
Registered User
Posts: 3045
Joined: Sun Mar 23, 2003 6:22 pm
Location: Franconia
Name: Martin Truckenbrodt
Contact:

Re: Enable Browser Language Detection

Post by Martin Truckenbrodt »

Hello Daniel_L,
you have not to customize my MOD. The feature you want to have still is included.

I doesn't matter if the browser is sending en_GB or only en. Although it doesn't matter if language pack en_gb or en_us or both are installed. The browser language detection always looks for the best result. The result have not to be "equal", "similar to" is enough and the end of the detection process.

And if you haven't installed the need language pack or if the browser is not sending a language information then the board default language is used for guests.

And if a registered user is logged in into the board then its personal language setting from the UCP is used.

Bye Martin
Free tutorial: Installing MODs in phpBB 3.0
Advanced Block MOD - Prevent spam on your phpBB 3.0 board with Stop Forum Spam, BotScout, Akismet, Project Honey Pot and several IP-RBL and Domain-RBL DNS blacklists!
My MODs
Use the official phpBB Ideas to vote missing core features!!!
Daniel_L
Registered User
Posts: 113
Joined: Fri Jan 04, 2008 3:01 pm

Re: Enable Browser Language Detection

Post by Daniel_L »

I've made the changes but it's not working, still showing only in english.

The last thing to do says to find:

Code: Select all

		$user['user_lang'] = $config['default_lang']
and add after

Code: Select all

 = $lang
so I end with

Code: Select all

$user['user_lang'] = $config['default_lang'] = $lang;
Normal?
Successfully running phpBB 3 on an association website since Feb 25th of 2008.
I'm a voluntarily webmaster.
User avatar
Martin Truckenbrodt
Registered User
Posts: 3045
Joined: Sun Mar 23, 2003 6:22 pm
Location: Franconia
Name: Martin Truckenbrodt
Contact:

Re: Enable Browser Language Detection

Post by Martin Truckenbrodt »

Hello Daniel_L;
this is correct. But this line is not a important line.

How many language packs have you installed at your board? Are these langauge packs really installed and activated?
Have you always purged the board after uploading modified files?
Have you always done your tests with new browser sessions?

Please don't forget that browser language detection is running only for guests and not for logged in registered users. So you have to be logged out to test it.

Bye Martin
Free tutorial: Installing MODs in phpBB 3.0
Advanced Block MOD - Prevent spam on your phpBB 3.0 board with Stop Forum Spam, BotScout, Akismet, Project Honey Pot and several IP-RBL and Domain-RBL DNS blacklists!
My MODs
Use the official phpBB Ideas to vote missing core features!!!
Daniel_L
Registered User
Posts: 113
Joined: Fri Jan 04, 2008 3:01 pm

Re: Enable Browser Language Detection

Post by Daniel_L »

Martin Truckenbrodt wrote:How many language packs have you installed at your board? Are these langauge packs really installed and activated?
2, en/fr
Have you always purged the board after uploading modified files?
yes, cache is not active for now...
Have you always done your tests with new browser sessions?
of course

I double checked the modifications I made but guess what, seems I ignore the very first one as I thought it was a comment only and was to add it only if I decided to keep the mod.

**/ made all the difference!

Thanks and Happy Holidays!
Successfully running phpBB 3 on an association website since Feb 25th of 2008.
I'm a voluntarily webmaster.
Daniel_L
Registered User
Posts: 113
Joined: Fri Jan 04, 2008 3:01 pm

Re: Enable Browser Language Detection

Post by Daniel_L »

Would someone help me add a little extra?

I'd like to know how I could use the result of this mod to display the board description in the proper language.

I'm playing in the overall_header.html file and wanted to add an IF statement but I have no idea how to read the lang$ variable. And does lang$ actually result in 2 letters only?

Would something like this close to be working? I guess I'm mixing java/php and everything but you get the idea what I'm looking for.

Code: Select all

<!-- IF LANG == "fr" -->  {FR_DESCRIPTION}  <!-- ENDIF -->
<!-- IF LANG == "en" -->  {EN_DESCRIPTION}  <!-- ENDIF -->
Does that make sense?

Thanks for any help.
Successfully running phpBB 3 on an association website since Feb 25th of 2008.
I'm a voluntarily webmaster.
Daniel_L
Registered User
Posts: 113
Joined: Fri Jan 04, 2008 3:01 pm

Re: Enable Browser Language Detection

Post by Daniel_L »

It's quiet here with the Holidays! ;)
Successfully running phpBB 3 on an association website since Feb 25th of 2008.
I'm a voluntarily webmaster.
Tuxman
Registered User
Posts: 420
Joined: Sun Jun 08, 2003 6:24 pm
Location: Germany
Contact:

Re: Enable Browser Language Detection

Post by Tuxman »

*scream* :D
[ randomly phpBBing ]
User avatar
Martin Truckenbrodt
Registered User
Posts: 3045
Joined: Sun Mar 23, 2003 6:22 pm
Location: Franconia
Name: Martin Truckenbrodt
Contact:

Re: Enable Browser Language Detection

Post by Martin Truckenbrodt »

Hello,
the MOD author has a family, too. And Christmas is family time. ;)

You have to use the full lang_iso name. On my website you can find an example for nearly the same thing.

E.g. for the first edit although you can use

Code: Select all

		'L_DE'					=> ($user->data['user_lang'] == 'de') ? true : false,
		'L_EN'					=> ($user->data['user_lang'] == 'en' || $user->data['user_lang'] == 'en_us') ? true : false,
if you have installed both British English and American English language pack at your board.

Bye Martin
Free tutorial: Installing MODs in phpBB 3.0
Advanced Block MOD - Prevent spam on your phpBB 3.0 board with Stop Forum Spam, BotScout, Akismet, Project Honey Pot and several IP-RBL and Domain-RBL DNS blacklists!
My MODs
Use the official phpBB Ideas to vote missing core features!!!
Daniel_L
Registered User
Posts: 113
Joined: Fri Jan 04, 2008 3:01 pm

Re: Enable Browser Language Detection

Post by Daniel_L »

Hi Martin,

Was looking for help by anyone with more knowledge than me but glad you replied.

Doesn't your script return a 2 letters only language code?

EDIT:

I tried

Code: Select all

'L_EN'               => ($user->data['user_lang'] == 'en') ? true : false,
 'L_FR'               => ($user->data['user_lang'] == 'fr') ? true : false,
and it works so I think there is no need to supply all fr-xx variant.

Thanks again
Successfully running phpBB 3 on an association website since Feb 25th of 2008.
I'm a voluntarily webmaster.
User avatar
Martin Truckenbrodt
Registered User
Posts: 3045
Joined: Sun Mar 23, 2003 6:22 pm
Location: Franconia
Name: Martin Truckenbrodt
Contact:

Re: Enable Browser Language Detection

Post by Martin Truckenbrodt »

Hello Daniel,
for my code you need the lang_iso name of the phpBB3 language pack. This is the name of the folder under <phpbb_root>/language and not the name of language the browser is submitting.

If you really want use the browser languages insteat then you have to program it yourself. For this you have to write own code or to at least modify my MOD a little bit to get put the value into a variable for your need.

Bye Martin
Free tutorial: Installing MODs in phpBB 3.0
Advanced Block MOD - Prevent spam on your phpBB 3.0 board with Stop Forum Spam, BotScout, Akismet, Project Honey Pot and several IP-RBL and Domain-RBL DNS blacklists!
My MODs
Use the official phpBB Ideas to vote missing core features!!!
BiometriOnline
Registered User
Posts: 3
Joined: Fri Jan 15, 2010 1:56 pm

Re: Enable Browser Language Detection for 3.06

Post by BiometriOnline »

Hi,

Thanks for this wonderful mod.

I was using an old version (1.05) on a multilanguage forum with phpbb 3.05

I have update the forum to 3.06, not with a fuion method but by using the news files (I decide to have clean files). So I have to applied again somme modification, just this mod and my own modification

I tried the 1.2.2 version of this mod with phpbb 3.06 but I have some problems.

I am going to try again, perhaps I've done a mistake

or perhaps it does'nt work with 3.06 ?

Is this mod working fine with version 3.0.6 ?



Thanks.
User avatar
Martin Truckenbrodt
Registered User
Posts: 3045
Joined: Sun Mar 23, 2003 6:22 pm
Location: Franconia
Name: Martin Truckenbrodt
Contact:

Re: Enable Browser Language Detection

Post by Martin Truckenbrodt »

Hello BiometriOnline,
as I've posted above this MOD still is compatible with phpBB 3.0.6 . Please check the file edits again. And then purge the board cache.

Bye Martin
Free tutorial: Installing MODs in phpBB 3.0
Advanced Block MOD - Prevent spam on your phpBB 3.0 board with Stop Forum Spam, BotScout, Akismet, Project Honey Pot and several IP-RBL and Domain-RBL DNS blacklists!
My MODs
Use the official phpBB Ideas to vote missing core features!!!
BiometriOnline
Registered User
Posts: 3
Joined: Fri Jan 15, 2010 1:56 pm

Re: Enable Browser Language Detection

Post by BiometriOnline »

Thanks,

It's work

The winner of my mistake is : I have forgot a ";"
in the folloing modifications

Open: style.php
Find
$user['user_lang'] = $config['default_lang'];

In-line Find
$user['user_lang'] = $config['default_lang']

In-line Add after
= $lang

And other idea is perhaps to write

Find
$user['user_lang'] = $config['default_lang'];

Replace by
$user['user_lang'] = $config['default_lang'] = $lang;

For the fun, I use 23 languages

Very good tool


Didier
User avatar
Martin Truckenbrodt
Registered User
Posts: 3045
Joined: Sun Mar 23, 2003 6:22 pm
Location: Franconia
Name: Martin Truckenbrodt
Contact:

Re: Enable Browser Language Detection

Post by Martin Truckenbrodt »

Hello Didier,
thank you very much for the feedback!

MOD validators don't like REPLACE-WITH actions. The reason is that REPLACE-WITH action can be bad for compatibility with other MODs when the some code is edited by several MODs.

Bye Martin
Free tutorial: Installing MODs in phpBB 3.0
Advanced Block MOD - Prevent spam on your phpBB 3.0 board with Stop Forum Spam, BotScout, Akismet, Project Honey Pot and several IP-RBL and Domain-RBL DNS blacklists!
My MODs
Use the official phpBB Ideas to vote missing core features!!!
Locked

Return to “[3.0.x] MOD Database Releases”