Skip to main content

Documentation: Domain per Language plugin

Links in other extensions

This article is for developers. Inside a normal page you never have to do anything: the plugin makes sure every link to another language domain is a complete URL before the page is sent. It matters when your code stores a URL, mails it, or writes it to a file.

Why a link needs resolving

Joomla's router builds links for the current request and always keeps the host of that request. A link to a page in another language therefore leaves the router with a marker in its path, which the plugin replaces with the domain of that language while the page is finished.

A URL that leaves the request before that moment keeps the marker. That happens when a scheduled task writes a sitemap, when an extension mails a link, or when an API hands URLs to another system.

Resolving a URL yourself

The plugin exposes one static method for this. Guard it with class_exists() so your extension keeps working when Domain per Language is not installed:

use Joomill\Plugin\System\Domainperlanguage\Extension\Domainperlanguage;

$url = Route::link('site', 'index.php?option=com_content&view=article&id=42&lang=nl', false, 0, true);

if (class_exists(Domainperlanguage::class)) {
    $url = Domainperlanguage::resolveUrl($url);
}

It accepts a single URL or a whole text containing URLs, and returns it with every marker replaced by the right domain. When the plugin is disabled or no domains are configured, it returns the input unchanged, so calling it is always safe.

If a marker slips through anyway

A URL with a marker that reaches a visitor still works: the plugin answers it with a permanent redirect to the same page on the right domain. A link in an old e-mail therefore never ends in a 404. Resolving is about clean URLs, not about broken ones.

Both editions

This method is part of the free edition as well, so an extension that supports Domain per Language works for every user of the plugin.