How can I localize a URL in a plugin? UrlHelper::getUrl() doesn't appear to take the current locale ID into account when generating a URL. Absolute URLs are fine as it handles that but is there a best practice way to localize relative Urls such as /foo/bar or foo/bar?
You can use UrlHelper::getSiteUrl() instead, which does have a $localeId argument, for generating a URL relative to a given locale’s base URL (per the siteUrl config setting).

So if your siteUrl config setting is set to:



'siteUrl' =&gt; array(
    'en' =&gt; 'http://example.com/',
    'de' =&gt; 'http://example.com/de/',
)


and you do this:

UrlHelper::getSiteUrl('foo/bar', null, null, 'de');


it will return this:

http://example.com/de/foo/bar


(Regardless of which site you call it from.)

UrlHelper::getSiteUrl() is also available to Twig templates via a siteUrl() global function:

{{ siteUrl('foo/bar', null, null, 'de') }}