Page::url() should return translated url?

Page::url() should return translated url? If not, how can I get the page url by name in the desired locale?

Hi @Cryden

Do you mean RainLab.Pages Page or a CMS module Page?

CMS module Page. there Page - October CMS

No, this won’t translate the URL since it accesses the router directly.

The CMS is unaware of the translation feature since it is introduced by the RainLab.Translate plugin. This works by hooking the Page object and changing its URL – something unrelated to the router.

The Translate plugin will need to provide an interface for this. Something like this

// RainLab\Translate\Classes\Locale

public static function transUrl($name, $params = [], $locale = null)
{
    if (empty($name) || !$page = \Cms\Classes\Page::find($name)) {
        return null;
    }

    if (!$locale) {
        $locale = static::getSiteLocaleFromContext();
    }

    $url = array_get($this->model->attributes, 'viewBag.localeUrl.'.$locale, $page->url);

    $router = new \October\Rain\Router\Router;

    $path = $router->urlFromPattern($urlPattern, $params);

    return \Cms::url($path);
}

I don’t know if it works, but its a start…