Skip to content

Commit

Permalink
[imp] Implementing the choice to not use a language cookie in
Browse files Browse the repository at this point in the history
multilanguage
  • Loading branch information
infograf768 committed Nov 16, 2014
1 parent 069de6c commit 0c33974
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
Expand Up @@ -9,14 +9,15 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_DESC="Add alternate meta tags for
PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL="Add alternate meta tags"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_AUTOMATIC_CHANGE_DESC="This option will automatically change the content language used in the frontend when a user site language is changed"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_AUTOMATIC_CHANGE_LABEL="Automatic Language Change"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_DESC="Language cookies can be set to expire at the end of the session or after a year. Default is a year."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_DESC="Language cookies can be set to expire at the end of the session or after a year. Default is session.<br /> If set to None the behaviour will depend on the "_QQ_"Language Selection for new Visitors"_QQ_" setting."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL="Cookie Lifetime"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_DESC="Choose Site default language or try to detect the browser settings language. It will default to site language if browser settings can't be found."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_LABEL="Language Selection for new Visitors."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_DESC="This option will allow item associations when switching from one language to another"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item associations"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_DESC="Remove the defined URL Language Code of the Content Language that corresponds to the default site language when Search Engine Friendly URLs is set to 'Yes'."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_LABEL="Remove URL Language Code"
PLG_SYSTEM_LANGUAGEFILTER_OPTION_NONE="None"
PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION="Session"
PLG_SYSTEM_LANGUAGEFILTER_OPTION_YEAR="Year"
PLG_SYSTEM_LANGUAGEFILTER_SITE_LANGUAGE="Site Language"
Expand Down
47 changes: 30 additions & 17 deletions plugins/system/languagefilter/languagefilter.php
Expand Up @@ -114,12 +114,15 @@ public function __construct(&$subject, $config)
{
$lang_code = self::$sefs[$sef]->lang_code;

// Create a cookie.
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('cookie_domain', '');
$cookie_path = $conf->get('cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
$app->input->cookie->set(JApplication::getHash('language'), $lang_code);
if ($this->params->get('lang_cookie', 1) != 2)
{
// Create a cookie.
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('cookie_domain', '');
$cookie_path = $conf->get('cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
$app->input->cookie->set(JApplication::getHash('language'), $lang_code);
}

// Set the request var.
$app->input->set('language', $lang_code);
Expand Down Expand Up @@ -275,8 +278,12 @@ public function buildRule(&$router, &$uri)
public function parseRule(&$router, &$uri)
{
$app = JFactory::getApplication();
$lang_code = null;

$lang_code = $app->input->cookie->getString(JApplication::getHash('language'));
if ($this->params->get('lang_cookie', 1) != 2)
{
$lang_code = $app->input->cookie->getString(JApplication::getHash('language'));
}

// No cookie - let's try to detect browser language or use site default.
if (!$lang_code)
Expand Down Expand Up @@ -463,11 +470,14 @@ public function onUserAfterSave($user, $isnew, $success, $msg)
);
self::$tag = $lang_code;

// Create a cookie.
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('cookie_domain', '');
$cookie_path = $conf->get('cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
if ($this->params->get('lang_cookie', 1) != 2)
{
// Create a cookie.
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('cookie_domain', '');
$cookie_path = $conf->get('cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
}
}
}
}
Expand Down Expand Up @@ -515,11 +525,14 @@ public function onUserLogin($user, $options = array())
// Change language.
self::$tag = $lang_code;

// Create a cookie.
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('cookie_domain', '');
$cookie_path = $conf->get('cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
if ($this->params->get('lang_cookie', 1) != 2)
{
// Create a cookie.
$conf = JFactory::getConfig();
$cookie_domain = $conf->get('cookie_domain', '');
$cookie_path = $conf->get('cookie_path', '/');
setcookie(JApplication::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
}

// Change the language code.
JFactory::getLanguage()->setLanguage($lang_code);
Expand Down
12 changes: 7 additions & 5 deletions plugins/system/languagefilter/languagefilter.xml
Expand Up @@ -55,14 +55,16 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="lang_cookie" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL"
<field
name="lang_cookie"
type="list"
default="0"
class="btn-group btn-group-yesno"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_LABEL"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_COOKIE_DESC"
>
<option value="1">PLG_SYSTEM_LANGUAGEFILTER_OPTION_YEAR</option>
<option value="2">PLG_SYSTEM_LANGUAGEFILTER_OPTION_NONE</option>
<option value="0">PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION</option>
<option value="1">PLG_SYSTEM_LANGUAGEFILTER_OPTION_YEAR</option>
</field>
<field name="alternate_meta" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_DESC"
Expand Down

0 comments on commit 0c33974

Please sign in to comment.