Skip to content

Commit

Permalink
Language2domain 1.1.0 - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pe7er committed Jan 12, 2021
1 parent 3c99b25 commit 0bb0d5a
Show file tree
Hide file tree
Showing 24 changed files with 2,177 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
build/tmp
source/.idea
.idea
44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
# Language Domains plugin for Joomla
# Language2Domain - System Plugin for Joomla

## UNMAINTAINED PROJECT
This project is no longer maintained. Any issues will not be actively picked up. Pull Requests will be merged unchecked. The sources here are up-for-grabs.
This plugin is for multilingual Joomla websites to make every language available under its own domain name.

It was originally developed as "Language Domains" by Jisse Reitsma, author of Programming Joomla! Plugins.
Jisse no longer maintains his "Language Domains" plugin because of lack of time due to his other work:
Jisse is expert in Magento 2, Shopware 6, React and Vue and can be hired via his company https://yireo.com.

Language2Domain is a modified version by Peter Martin (https://db8.nl) to work with Joomla 3.9, PHP 7.4 and Name Spacing,
and it has been adapted to the Joomla 3.9 Code Style.
It has been renamed to "Language2Domain" to avoid confusion with the original plugin.

## Background
Peter created a website about the best practises for websites: https://the-best-website.com.
The website describes what you can do to improve it for visitors and its administrators.
Furthermore, it discusses all kinds of tests to test its best practises.

He wanted to make his multilingual Joomla 3.9 website available with each of its languages under its own domain name.
Therefore, Peter modified the plugin. Now the website (one instance) is available under 5 different languages/domain names:
- English: The best website: https://the-best-website.com/
- German: Die beste Website: https://die-beste-website.de/
- French: Le meilleur site web: https://le-meilleur-site-web.fr/
- Spanish: El mejor sitio web: https://el-mejor-sitio-web.es/
- Dutch: De beste website: https://de-beste-website.nl/

## Disclaimer
This plugin works as is. It works with the Joomla core but has NOT been tested with all available extensions
It's released under the GNU GPL license.

## Introduction
This Joomla 3 plugin allows you to assign a domain per lanuage. You configure specific "bindings" in the parameters of this plugin. Each line contains a binding between a language-tag and a domain. The plugin checks whether the current domain matches the specified language, and redirects to the neccessary domain if needed. Also, it will try to fix all of the generated Joomla! SEF URLs.
This Joomla 3 plugin allows you to assign a domain per language. You configure specific "bindings" in the parameters of this plugin. Each line contains a binding between a language-tag and a domain. The plugin checks whether the current domain matches the specified language, and redirects to the neccessary domain if needed. Also, it will try to fix all of the generated Joomla! SEF URLs.

## Installation
* Make sure Joomla! SEF is fully enabled
Expand All @@ -14,7 +38,7 @@ This Joomla 3 plugin allows you to assign a domain per lanuage. You configure sp
* Configure this plugin for the proper bindings.

## Usage
For example you could configure the following bindings:
For example, you could configure the following bindings:

en-GB=example.co.uk
fr-FR=example.fr
Expand All @@ -25,7 +49,7 @@ You can also specify additional domains like this:

nl-NL=example.nl|www.example.nl

This will enforce the language Dutch to the domain `example.nl` while any request to `www.example.nl` will also redirect to `example.nl`. So, the first domain in the column-separated list is considered the primary domain for that language.
This will enforce the language Dutch to the domain `example.nl` while any request to `www.example.nl` will also redirect to `example.nl`. So, the first domain in the column-separated list is the primary domain for that language.

Note that this plugin treats domains and subdomains as the same thing.

Expand All @@ -45,7 +69,7 @@ Make sure to remove all cookies when you are testing with this plugin. Alternati

Make sure to disable the System - Language Filter plugin, when this plugin is enabled.

When using caching, beware of using the Sytem - Cache plugin. Under Joomla! 2.5, that plugin does not cache content on a domain-level, so therefor all cache is the same for all domains. Simply put, plugins like ours are not compatible with the System - Cache plugin under Joomla! 2.5. Under Joomla! 3, using the cache-plugin is definitely possible. Test things first with the cache-plugin disabled. If you are enabling the plugin, make sure its ordering is higher than this System - Language Domains plugin - so that the cache-plugin is loaded after this plugin. Also make sure to wipe out the page-cache by using the Cache Manager.
When using caching, beware of using the Sytem - Cache plugin. Under Joomla! 2.5, that plugin does not cache content on a domain-level, therefore all cache is the same for all domains. Simply put, plugins like ours are not compatible with the System - Cache plugin under Joomla! 2.5. Under Joomla! 3, using the cache-plugin is definitely possible. Test things first with the cache-plugin disabled. If you are enabling the plugin, make sure its ordering is higher than this System - Language Domains plugin - so that the cache-plugin is loaded after this plugin. Also make sure to wipe out the page-cache by using the Cache Manager.

When using the System - SEF plugin to translate links in your content, make sure it is loaded after the Language Domains plugin.

Expand All @@ -55,15 +79,15 @@ We have not made any effort to make this plugin compatible with JoomFish and Fal
We do not provide support for the combination of our plugin and Falang. You can still check the Troubleshooting section on the plugin page to see if you can make things work.

## FAQ: Does this plugin aid to SEO?
According to some SEO readings on the web, having a website that is matching the offered language with the choosen domain-suffix (TLD or top-level domainname) has a beneficial effect on your SEO. This means that if you have German website with a domainname ending with .de (German TLD), this website would be preferred over the same German website with a domainname ending with .fr (French TLD).
According to some SEO readings on the web, having a website that is matching the offered language with the chosen domain-suffix (TLD or top-level domain name) has a beneficial effect on your SEO. This means that if you have German website with a domainname ending with .de (German TLD), this website would be preferred over the same German website with a domainname ending with .fr (French TLD).

This is what others are saying. But we are not able to confirm this or unconfirm this. We are simply developing cool plugins. Tuning of SEO is where you come in. If you want know whether this actually has an effect on SEO, either experiment with it (as SEO experts do already) or reconfirm what we have read on the web.

## FAQ: Will my site be indexed on all languages on all domains?
## FAQ: Is my site indexed on all languages on all domains?
We don't know the structure of your site, so we can't answer this question either. If you want to know what is being indexed, scan your site for links. If a language-link is there, and it can be followed, without switching domains, it might be a bug in our plugin and we are happy to fix that.

## FAQ: Should all the domains point to the same Joomla! site?
Yes. You need one Joomla! site with multiple languages and multiple domains. Before installing this plugin, make sure that all domains actually point to the same Joomla! site. Also make sure that all languages are working and are switching properly. If everything is configured properly, then you are ready to install and configure this plugin.

## FAQ: Can I also use this for my subdomains?
Yes. As far as this plugin is concerned, a domain-name and a subdomain are the same thing.
Yes. For this plugin, a domain-name and a subdomain are the same thing.
167 changes: 167 additions & 0 deletions src/plugins/system/language2domain/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php
/**
* Joomla! System plugin - Language 2 Domain
* Originally developed by Jisse Reitsma, https://yireo.com
* Modified by Peter Martin, https://db8.nl
*
* @author Yireo <[email protected]>
* @author Peter Martin <[email protected]>
* @copyright Copyright 2016 Yireo.com. All rights reserved
* @license GNU Public License
* @link https://db8.nl
*/

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Version;

defined('_JEXEC') or die;

/**
* Class PlgSystemLanguage2DomainHelper
*
* @since 1.0.0
*/
class PlgSystemLanguage2DomainHelper
{
/**
* Method to detect whether Falang is active or not
*
* @return boolean
* @since 1.0.0
*/
public function isFalangDatabaseDriver()
{
$db = Factory::getDbo();

if ($db instanceof JFalangDatabase)
{
return true;
}

return false;
}

/**
* Helper-method to get a proper URL from the domain
*
* @param string $url URL to obtain the domain from
*
* @return string
* @since 1.0.0
*/
public function getDomainFromUrl($url)
{
// Add URL-elements to the domain
if (preg_match('/^(http|https):\/\/([a-zA-Z0-9\.\-\_]+)/', $url, $match))
{
$domain = $match[2];

return $domain;
}

return false;
}

/**
* Helper-method to get a proper URL from the domain
*
* @param string $domain Domain to obtain the URL from
*
* @return string
* @since 1.0.0
*/
public function getUrlFromDomain($domain)
{
// Add URL-elements to the domain
if (preg_match('/^(http|https):\/\//', $domain) == false)
{
$domain = ($this->isSSL()) ? 'https://' . $domain : 'http://' . $domain;
}

if (preg_match('/\/$/', $domain) == false)
{
$domain = $domain . '/';
}

$config = Factory::getConfig();

if ($config->get('sef_rewrite', 0) == 0 && preg_match('/index\.php/', $domain) == false)
{
$domain = $domain . 'index.php/';
}

return $domain;
}

/**
* Method to override certain Joomla classes
*
* @return void
* @since 1.0.0
*/
public function overrideClasses()
{
JLoader::import('joomla.version');
$version = new Version;
$majorVersion = $version->getShortVersion();

if (version_compare($majorVersion, '3.2', 'ge'))
{
require_once JPATH_SITE . '/plugins/system/language2domain/rewrite-32/associations.php';
require_once JPATH_SITE . '/plugins/system/language2domain/rewrite-32/multilang.php';
}
}

/**
* Reset the current language (with $%& VirtueMart support)
*
* @return void
* @since 1.0.0
*/
public function resetDefaultLanguage()
{
if (!class_exists('VmConfig'))
{
$vmConfigFile = JPATH_ROOT . '/administrator/components/com_virtuemart/helpers/config.php';

if (file_exists($vmConfigFile))
{
defined('DS') or define('DS', DIRECTORY_SEPARATOR);

include_once $vmConfigFile;
}
}

if (class_exists('VmConfig'))
{
VmConfig::loadConfig();
VmConfig::$vmlang = false;
VmConfig::setdbLanguageTag();
}
}

/**
* Helper-method to check whether SSL is active or not
*
* @return boolean
* @since 1.0.0
*/
protected function isSSL()
{
// Support for proxy headers
if (isset($_SERVER['X-FORWARDED-PROTO']))
{
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
{
return true;
}

return false;
}

$uri = Uri::getInstance();

return (bool) $uri->isSSL();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; Language2Domain - System Plugin
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_LANGUAGE2DOMAIN="System - Language2Domain"
PLG_SYSTEM_LANGUAGE2DOMAIN_DESC="For multilingual Joomla Websites to associate Languages with Domains"

PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_BINDINGS_LABEL="Bindings"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_BINDINGS_DESC="List of language-code versus domain. Each record on a new line. Language and domain separated by equal-sign. e.g.: en-GB=example.co.uk and nl-NL=example.nl"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_ENFORCE_DOMAINS_LABEL="Enforce domains"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_ENFORCE_DOMAINS_DESC="Make sure current domain matches one of the domains configured here"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_EXCLUDE_COMPONENTS_LABEL="Exclude Components"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_EXCLUDE_COMPONENTS_DESC="Comma-separated list of components that should be just served from current domain"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_EXCLUDE_URLS_LABEL="Exclude URLS"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_EXCLUDE_URLS_DESC="Comma-separated list of URLs that should be just served from current domain"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_LOAD_BUILDRULE_LABEL="Load Build Rule"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_LOAD_BUILDRULE_DESC="Only enable this, if you are using Falang and you want to see whether this works or not"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_DEBUG_LABEL="Debug"
PLG_SYSTEM_LANGUAGE2DOMAIN_FIELD_DEBUG_DESC="Add debugging messages to JS console"

PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_LABEL="Item associations"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_ITEM_ASSOCIATIONS_DESC="This option will allow item associations when switching from one language to another"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_LABEL="Add alternate meta tags"
PLG_SYSTEM_LANGUAGEFILTER_FIELD_ALTERNATE_META_DESC="Add alternate meta tags for items with associated items in other languages."

JIGNORE="Ignore"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; Language2Domain - System Plugin
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_LANGUAGE2DOMAIN="System - Language2Domain"
PLG_SYSTEM_LANGUAGE2DOMAIN_DESC="For multilingual Joomla Websites to associate Languages with Domains"
Loading

0 comments on commit 0bb0d5a

Please sign in to comment.