[INFO] Code Example

[INFO] Code Example

Postby MartinTruckenbrodt » 18 Feb 2010, 22:41

Hello,
here is the changed code after installing the MOD.
./includes/session.php:
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.
			* language checking added 2008-08-15 by Martin Truckenbrodt
			**/

			if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
			{
				$lang_iso_xx_yy = array();
				$lang_iso_xx = array();
				$accept_lang_xx_yy = array();
				$accept_lang_xx = array();

				$sql = 'SELECT lang_iso FROM ' . LANG_TABLE;
				$result = $db->sql_query($sql, 3600);

				while ($row = $db->sql_fetchrow($result))
				{
					if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . "/common.$phpEx"))
					{
						$lang_iso_xx_yy[] = $row['lang_iso'];
						if (strlen($row['lang_iso']) > 4)
						{
							$lang_iso_xx[$row['lang_iso']] = substr($row['lang_iso'], 0, 2);
						}
					}
				}

				$accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);

				foreach ($accept_lang_ary as $accept_lang)
				{
					// Set correct format ... guess full xx_yy form
					$accept_lang_xx_yy = basename(substr($accept_lang, 0, 2) . '_' . strtolower(substr($accept_lang, 3, 2)));
					// Set correct format ... guess only xx form
					$accept_lang_xx = basename(substr($accept_lang, 0, 2));

					// browser xx-YY == board xx_yy and
					// browser xx == board xx
					if (in_array($accept_lang_xx_yy, $lang_iso_xx_yy))
					{
						$this->lang_name = $config['default_lang'] = $accept_lang_xx_yy;
						break;
					}
					// browser xx-YY => xx == board xx
					else if (in_array($accept_lang_xx, $lang_iso_xx_yy))
					{
						$this->lang_name = $config['default_lang'] = $accept_lang_xx;
						break;
					}
					// browser xx == board xx_yy => xx
					else if (in_array($accept_lang_xx, $lang_iso_xx) && $lang_iso_xx != '')
					{
						$this->lang_name = $config['default_lang'] = array_search($accept_lang_xx, $lang_iso_xx);
						break;
					}
					// board default language
					else
					{
						$this->lang_name = $config['default_lang'];
					}
				}
				$this->data['user_lang'] = $this->lang_name;
			}
			/*
			*/


./style.php:
Code: Select all
$sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
$lang = (isset($_GET['lang'])) ? strval($_GET['lang']) : '';
...
Code: Select all
		$user['user_lang'] = $config['default_lang'] = $lang;


Just compare it if you have problems.

Bye Martin
MartinTruckenbrodt
Site Admin
 
Posts: 331
Joined: 14 Aug 2005, 16:28
Location: Germany - Souththuringia
first name: Martin

Return to Enable Browser Language Detection MOD

Who is online

Users browsing this forum: No registered users and 1 guest

cron