Document::getById(XXX) and multilingual


#1

Hi there,

In some case, the design of a website imposes me to display a link in the middle of nowhere (for example, a link “Create your account” inside a popup). In this case, I use this code:

<a href="<?= Document::getById(130) ?>"><?= $this->translate("Create your account"); ?></a> 

We are working now on the French version of the same website. Unfortunately, on the French version, this link is not automatically “translated” by Pimcore and displays the english URL.

Is there a native function or custom function that converts urls in the right language, based only on the ID?

For example, what I expect:
In English, <?= Document::myfunction(130) ?> should display the english (/en/signup)
In French, <?= Document::myfunction(130) ?> should display the french url (/en/inscription)

For your information, my page /en/signup is linked to /fr/inscription using the native button “Translation” (the one with 2 people and 2 blue flags), but on the French website <?= Document::getById(130) ?> still displays the English url.

Thanks you for your help!


#2

Document with ID 130 is always the English version, no matter what. There is a built in feature for document translations though, check the pimcore docs for that.


#3

Hello,

Thanks for your help, but if I post here, this is mean that I have not found the solution in the documentation.

Can you tell me more about it or do you have any example?

Best regard,
Jerome


#4

Hi @Kreeger,

Here are some references on this topic:
Localize and link your documents in between different languages, then get the translation for a specific document.

Hope this somewhat helps to understand what you need to do!