Language selection for anonymous users?

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Scam Warning
Locked
IronCrown
Registered User
Posts: 16
Joined: Thu Oct 18, 2007 6:34 am

Language selection for anonymous users?

Post by IronCrown »

I'm developing a site that primarily targets german users, but also international users. If all unregistered users see the board in English, my main audience will be alienated. If the default language is German however, most international users will not be able to understand anything. I need an option for anonymous users to select their language. Is this possible?

User avatar
pentapenguin
Former Team Member
Posts: 11030
Joined: Thu Jul 01, 2004 4:15 am
Location: GA, USA

Re: Language selection for anonymous users?

Post by pentapenguin »

That would take a MOD so I'll move this for you.

Topic moved to MOD Requests
Support Resources: Support Request Template
If you need professional assistance with your board, please contact me for my reasonable rates.

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: Language selection for anonymous users?

Post by igorw »

Open: includes/session.php

Find:

Code: Select all

			$this->lang_name = (file_exists($phpbb_root_path . 'language/' . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
After, add:

Code: Select all

			if ($lang_name = request_var('lang', ''))
			{
				$sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . '
						WHERE lang_dir = \'' . $db->sql_escape($lang_name) . '\'';
				$result = $db->sql_query($sql);
				$lang_exists = (bool) $db->sql_fetchfield('lang_id');
				$db->sql_freeresult($result);

				if ($lang_exists && file_exists($phpbb_root_path . 'language/' . basename($lang_name) . "/common.$phpEx"))
				{
					$this->lang_name = basename($lang_name);
				}
			}
Find:

Code: Select all

			$this->lang_name = basename($config['default_lang']);
After, add:

Code: Select all

			if ($lang_name = request_var('lang', ''))
			{
				$sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . '
						WHERE lang_dir = \'' . $db->sql_escape($lang_name) . '\'';
				$result = $db->sql_query($sql);
				$lang_exists = (bool) $db->sql_fetchfield('lang_id');
				$db->sql_freeresult($result);

				if ($lang_exists && file_exists($phpbb_root_path . 'language/' . basename($lang_name) . "/common.$phpEx"))
				{
					$this->lang_name = basename($lang_name);
				}
			}
Find:

Code: Select all

		if (!empty($_GET['style']) && $auth->acl_get('a_styles'))
		{
			global $SID, $_EXTRA_URL;

			$style = request_var('style', 0);
			$SID .= '&style=' . $style;
			$_EXTRA_URL = array('style=' . $style);
		}
		else
		{
			// Set up style
			$style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']);
		}
After, add:

Code: Select all

		if (!empty($lang_exists) && file_exists($phpbb_root_path . 'language/' . basename($lang_name) . "/common.$phpEx"))
		{
			global $SID, $_EXTRA_URL;

			$SID .= '&lang=' . urlencode($this->lang_name);
			$_EXTRA_URL[] = 'lang=' . urlencode($this->lang_name);
		}
Here's some more code that is required to make it work with imagesets:
Open: style.php
Find:

Code: Select all

	if ($user['user_id'] == ANONYMOUS)
	{
		$user['user_lang'] = $config['default_lang'];
	}
After, add:

Code: Select all

	if (!empty($_GET['lang']))
	{
		$user['user_lang'] = basename((string) $_GET['lang']);
	}
Open: includes/functions.php
Find:

Code: Select all

'T_STYLESHEET_LINK'		=>
In-line find:

Code: Select all

$user->data['user_lang']
In-line replace with:

Code: Select all

(isset($_GET['lang']) ? urlencode(request_var('lang', '')) : $user->data['user_lang'])
With that added, you can specify the lang parameter in the url, for example: index.php?lang=en
Last edited by igorw on Thu Apr 24, 2008 9:09 pm, edited 4 times in total.
Reason: Updated
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

BondGamer
Registered User
Posts: 435
Joined: Mon Dec 15, 2003 7:49 pm
Contact:

Re: Language selection for anonymous users?

Post by BondGamer »

Evil, would that change make it so once the user is on the forum, every link they visit will keep their language preference? Or would further changes need to be made to the append_url function?
My phpBB3 Mods: - None active =[

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: Language selection for anonymous users?

Post by igorw »

Further changes would be required for that, allthough not to the append_sid() function :)

Edit: code above.

That should append it to the url :)
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

BondGamer
Registered User
Posts: 435
Joined: Mon Dec 15, 2003 7:49 pm
Contact:

Re: Language selection for anonymous users?

Post by BondGamer »

This might be a good feature to add in version 3.2 of Olympus.
My phpBB3 Mods: - None active =[

User avatar
pentapenguin
Former Team Member
Posts: 11030
Joined: Thu Jul 01, 2004 4:15 am
Location: GA, USA

Re: Language selection for anonymous users?

Post by pentapenguin »

BondGamer wrote:This might be a good feature to add in version 3.2 of Olympus.
Be sure to suggest it then when the features tracker comes back. :)
Support Resources: Support Request Template
If you need professional assistance with your board, please contact me for my reasonable rates.

cunyalen
Registered User
Posts: 127
Joined: Sat Jul 14, 2007 9:09 pm

Re: Language selection for anonymous users?

Post by cunyalen »

Hi evil, I tried your MOD. I have Chinese language on my forum. The language folder is named as zh_cmn_hans. So I need put the url as http://www.domain.com/index.php?lang=zh_cmn_hans, right? I tried, but it didn't work. I wonder why.

By the way, I have the phpbb3 portal as my homepage. Can I use the url like http://www.domain.com/bb3portal.php?lang=zh_cmn_hans also?

Thanks a lot.

User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: Language selection for anonymous users?

Post by igorw »

Hmm, i didn't test my code to be honest, i was assuming that would work... but that is supposed to be correct... :?
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three

cunyalen
Registered User
Posts: 127
Joined: Sat Jul 14, 2007 9:09 pm

Re: Language selection for anonymous users?

Post by cunyalen »

Thanks for your quick response.
So for the 2ndd part of my question, what do you think?
bb3portal.php?lang=en will also work not or?

ameeck
Former Team Member
Posts: 6559
Joined: Mon Mar 21, 2005 6:57 pm

Re: Language selection for anonymous users?

Post by ameeck »

I haven't tested it yet, but it seems phpBB actually has the code needed for language auto-detection for guests, you just have to uncomment it.
Find:

Code: Select all

/**
			* If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
			* If re-enabled we need to make sure only those languages installed are checked
			* Commented out so we do not loose the code.
Add this after it:

Code: Select all

*/
Then find the next

Code: Select all

	*/
and delete it...


As I said I haven't tested it and I don't know why it's commented, but I'll give it a thorough look tommorow if I'll have time.

User avatar
ApplePro
Registered User
Posts: 167
Joined: Wed Oct 31, 2007 1:27 pm

Re: Language selection for anonymous users?

Post by ApplePro »

Hello guys,

I've just tried this mod, I've inserted 3 blocks of code, but it didn't work for me.

For example, when I add &lang=ru or &lang=en to any phpBB3 URL, I get error message:

Code: Select all

Fatal error: Cannot unset string offsets in /home/re/phpBB3/includes/session.php on line 1773
1773 line is:

Code: Select all

unset($lang_dates['May_short']);
Also, board doesn't work now. When I go to index.php, for example, I get this error message:

Code: Select all

Fatal error: Cannot use string offset as an array in /home/re/phpBB3/includes/functions.php on line 3343
I wonder how can I fix it?

Did anyone try this mod already?

User avatar
UncleVIBES
Registered User
Posts: 64
Joined: Sat Jun 09, 2007 5:08 am
Location: France
Contact:

Re: Language selection for anonymous users?

Post by UncleVIBES »

ameeck wrote:I haven't tested it yet, but it seems phpBB actually has the code needed for language auto-detection for guests, you just have to uncomment it...

As I said I haven't tested it and I don't know why it's commented, but I'll give it a thorough look tommorow if I'll have time.
And it works very well on RC7 as described. Anonymous users see the forum instructions in theit lang if exist. Very cool before registering.
Last edited by UncleVIBES on Wed Nov 07, 2007 10:10 am, edited 1 time in total.

cunyalen
Registered User
Posts: 127
Joined: Sat Jul 14, 2007 9:09 pm

Re: Language selection for anonymous users?

Post by cunyalen »

I can't make it work yet. I'll never get an error no matter what language name I put in even though it doesn't exist. I just get english.

I have upgraded to RC7.

User avatar
UncleVIBES
Registered User
Posts: 64
Joined: Sat Jun 09, 2007 5:08 am
Location: France
Contact:

Re: Language selection for anonymous users?

Post by UncleVIBES »

ameeck wrote:I haven't tested it yet, but it seems phpBB actually has the code needed for language auto-detection for guests, you just have to uncomment it.
Find:

Code: Select all

/**
			* If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
			* If re-enabled we need to make sure only those languages installed are checked
			* Commented out so we do not loose the code.
Add this after it:

Code: Select all

*/
Then find the next

Code: Select all

	*/
and delete it...


As I said I haven't tested it and I don't know why it's commented, but I'll give it a thorough look tommorow if I'll have time.
I have tested it. It works perfectly with RC7 as described in the comments. For my international forum it's what I need for the registration & login steps.

Locked

Return to “[3.0.x] MOD Requests”