/** * Gets a URL for the specified locale. * * @param string $path * @param string|LocaleModel $locale * * @return string */ public function getUrlForLocale($path, $locale) { $this->validateLocale($locale); // Get the site URL for the current locale $siteUrl = craft()->siteUrl; if (UrlHelper::isFullUrl($path)) { // Return $path if it’s a remote URL if (!stripos($path, $siteUrl)) { return $path; } // Remove the current locale siteUrl $path = str_replace($siteUrl, '', $path); } // Get the site URL for the specified locale $localizedSiteUrl = craft()->config->getLocalized('siteUrl', $locale); // Trim slahes $localizedSiteUrl = rtrim($localizedSiteUrl, '/'); $path = trim($path, '/'); return UrlHelper::getUrl($localizedSiteUrl . '/' . $path); }