Domain based site localization

Locale can automatically determine which one of the configured availableLocales to use based on the domain the user is visiting. To do this, just add the domains key when configuring your availableLocales.

For example, imagine the main english version of your web site runs on the domain, and you want the spanish version of the website to run under Your Locale.config.php might look something like this:


namespace Cherrycake;

$LocaleConfig = [
	"availableLocales" => [
		"main" => [
			"domains" => [""],
			"language" => LANGUAGE_ENGLISH,
			"temperatureUnits" => TEMPERATURE_UNITS_FAHRENHEIT,
			"currency" => CURRENCY_USD,
			"decimalMark" => DECIMAL_MARK_POINT,
			"measurementSystem" => MEASUREMENT_SYSTEM_IMPERIAL,
			"timeZone" => TIMEZONE_ID_ETC_UTC
		"spain" => [
			"domains" => [""],
			"language" => LANGUAGE_SPANISH,
			"temperatureUnits" => TEMPERATURE_UNITS_CELSIUS,
			"currency" => CURRENCY_EURO,
			"decimalMark" => DECIMAL_MARK_COMMA,
			"measurementSystem" => MEASUREMENT_SYSTEM_METRIC,
	"defaultLocale" => "main",
	"canonicalLocale" => "main",

With this setup, the main locale will be automatically selected when visiting the site using the, and the spain locale when visiting via

Separating your website locales in different domains like this is one of the ways Google recommends to organize multilingual web sites for optimal SEO.

Automatically redirecting users to the matching locale domain

Google doesn't recommend performing an automatic redirection based on the user's perceived language or the geotargeting based on the client IP, and Locale doesn't implement such a mechanism for that reason.

Instead, you might want to give the user the option to switch to another language/localization of your site, specially if you've detected that it's different than the one he is currently visiting.

Let Google discover the different versions of your site

For SEO purposes, it's quite important to help Google discover the different versions of your site when you have multilingual sites. One of the recommended ways of doing so is by specifying alternate meta tags in your HTML HEAD section.

Last updated