Skip to content

Commit

Permalink
Set x-default-language header in language plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepereiradasilva authored and wilsonge committed Jan 21, 2016
1 parent 8fedeac commit 98aa6f5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ PLG_SYSTEM_LANGUAGEFILTER_FIELD_DETECT_BROWSER_DESC="Choose site default languag
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_XDEFAULT_DESC="This option will add x-default meta tag to improve SEO."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL="Add x-default Meta Tag"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_DESC="Choose the x-default language."
PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL="x-default Language"
PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE="Default frontend language"
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_SESSION="Session"
Expand Down
12 changes: 12 additions & 0 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,18 @@ public function onAfterDispatch()
{
$doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i));
}

// Add x-default language tag
if ($this->params->get('xdefault', 1))
{
$xdefault_language = $this->params->get('xdefault_language', $this->default_lang);
$xdefault_language = ( $xdefault_language == 'default' ) ? $this->default_lang : $xdefault_language;
if (isset($languages[$xdefault_language]))
{
// Use a custom tag because addHeadLink is limited to one URI per tag
$doc->addCustomTag('<link href="' . $server . $languages[$xdefault_language]->link . '" rel="alternate" hreflang="x-default" />');
}
}
}
}
}
Expand Down
41 changes: 31 additions & 10 deletions plugins/system/languagefilter/languagefilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="alternate_meta" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL"
default="1"
class="btn-group btn-group-yesno"
showon="item_associations:1"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="xdefault" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LABEL"
default="1"
class="btn-group btn-group-yesno"
showon="item_associations:1[AND]alternate_meta:1"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="xdefault_language" type="contentlanguage"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_XDEFAULT_LANGUAGE_LABEL"
default="default"
showon="item_associations:1[AND]alternate_meta:1[AND]xdefault:1"
>
<option value="default">PLG_SYSTEM_LANGUAGEFILTER_OPTION_DEFAULT_LANGUAGE</option>
</field>
<field name="remove_default_prefix" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_REMOVE_DEFAULT_PREFIX_LABEL"
Expand All @@ -62,16 +92,7 @@
<option value="1">PLG_SYSTEM_LANGUAGEFILTER_OPTION_YEAR</option>
<option value="0">PLG_SYSTEM_LANGUAGEFILTER_OPTION_SESSION</option>
</field>
<field name="alternate_meta" type="radio"
description="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_DESC"
label="PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL"
default="1"
class="btn-group btn-group-yesno"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>
</fields>
</config>
</extension>
</extension>

0 comments on commit 98aa6f5

Please sign in to comment.