User tests: Successful: Unsuccessful:
On certain websites there is no need to store user language even during session. I've added the option which adds this functionality.
Labels |
Added:
?
|
Category | ⇒ | Multilanguage |
No opposition.
Please alpha order the new string
Waiting the PR to be updated. Would be for 3.4.0
@infograf768,
I've updated the issue with the changes you requested
Hmm... thinking again, see http://www.w3schools.com/php/func_http_setcookie.asp
Example 3
Delete a cookie by setting the expiration date to a date/time in the past:
<?php // Set the expiration date to one hour ago setcookie ("TestCookie", "", time() - 3600); ?>
I did not see any change in fact when using your code. It behaved the same as Session here.
Please explain further why you need it on some sites, i.e. what it does precisely.
Maybe you do not want any cookie. In this case it would be better to add a conditional before everysetcookie
In any case the tip should be updated
You're right, i don't want to selected language cookie to be stored at all. When user selects non-default language (or if language selected automatically by joomla) and reopens website he will be automatically redirected to the index page of language which he selected previously. I have certain websites where non-default languages have secondary, minor role and used only as supporting landing pages to default language. In this case if user land on secondary-language page and reopens website later he must see default-language version.
I can add condition and just don't set cookie if "None" option has been selected. But if this feature will be added and selected on running website where all the users already have "Session" or "Year" cookies, they wont be deleted. I assume it will cause unexpected behaviour. And if i add logic which checks language cookie presence (getcookie) before deletion it will give same overhead as current logic (setcookie without all theese checks.
I'm not insisting on this point so if you need those checks and still find this feature useful, could you please tell me exactly what logic should i add.
This is what I propose. It works here. The result will evidently depend in the settings of "Language Selection for new Visitors" i.e. default site language or browser settings
diff --git a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini
index a41ace1..b24cd28 100644
--- a/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini
+++ b/administrator/language/en-GB/en-GB.plg_system_languagefilter.ini
@@ -10,5 +10,5 @@
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."
@@ -18,4 +18,5 @@
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"
diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php
index d9e4a72..200d66a 100644
--- a/plugins/system/languagefilter/languagefilter.php
+++ b/plugins/system/languagefilter/languagefilter.php
@@ -115,10 +115,13 @@
$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.
@@ -276,6 +279,10 @@
{
$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.
@@ -464,9 +471,12 @@
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);
+ }
}
}
@@ -516,9 +526,12 @@
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.
diff --git a/plugins/system/languagefilter/languagefilter.xml b/plugins/system/languagefilter/languagefilter.xml
index df486ee..63a2cb6 100644
--- a/plugins/system/languagefilter/languagefilter.xml
+++ b/plugins/system/languagefilter/languagefilter.xml
@@ -56,12 +56,14 @@
<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"
The version proposed in the original PR here does not fit.
The correct code is in:
#4911 (comment)
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-11-16 18:22:00 |
@infograf768 For you to decide