Skip to main content

Documentation: Domain per Language plugin

Links in other extensions

This article is for developers. On a normal page you never have to do anything: the plugin makes sure every link to another language domain is a complete address before the page is sent out.

It only matters when your own code stores an address, mails it, or writes it to a file.

Why an address needs resolving

Joomla's router builds links for the page you are on right now, and it always keeps the domain of that page. A link to another language therefore comes out of the router with a marker in its path. The plugin swaps that marker for the right domain while the page is being finished. How it works describes those three layers in more detail.

An address that leaves the page 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 addresses to another system.

Resolving an address yourself

The plugin has one static method for this. Wrap it in 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);
}

You can give it a single address or a whole piece of text with addresses in it. You get it back with every marker replaced by the right domain. When the plugin is off, or when no domains are set up, you get your input back unchanged. So calling it is always safe.

If a marker slips through anyway

An address with a marker in it still works when a visitor opens it. The plugin answers with a permanent redirect to the same page on the right domain, so a link in an old e-mail never ends on a 404 page.

Resolving is about clean addresses, not about broken ones.

Always available

This method is always part of the plugin. An extension that supports Domain per Language therefore works for everybody who uses the plugin.