PHP code example of xini / silverstripe-localedomains
1. Go to this page and download the library: Download xini/silverstripe-localedomains library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xini / silverstripe-localedomains example snippets
LocaleDomains::addLocaleDomain('de_DE', 'www.germandomain.de');
LocaleDomains::addLocaleDomain('en_GB', 'www.englishdomain.com');
LocaleDomains::addLocaleDomain('fr_FR', 'www.frenchdomain.fr');
public function Link($action=null) {
$link = parent::Link($action);
if($this->hasExtension('Translatable') && $this->hasExtension("LocaleDomainDecorator")){
// check base url and set localised domain if necessary
$currHost = Director::protocolAndHost();
$localeHost = Director::protocol().LocaleDomains::getHostFromLocale($this->Locale);
if ($currHost != $localeHost) {
$link = Controller::join_links($localeHost, $link);
}
}
return $link;
}