1

I am trying to make the URLs translatable according to the language selected for the site.

7
  • 1
    What do you mean with translatable? Do you want to translate the slug or do you want to change the complete URL format? Jan 29, 2018 at 9:53
  • Which one is the best and translatable? Jan 30, 2018 at 10:44
  • I'm not sure what you want to know. You have to insert different values for different languages nothing more and nothing less. It's like every other field in Craft. Maybe you have to explain your issue properly Jan 30, 2018 at 10:53
  • I have site in 2 different languages english and dutch, for example One single entry for About Us so its english/dutch URL is www.demo.com/about-us but i want dutch url like www.demo.com/over-ons Jan 30, 2018 at 11:00
  • Ok, then go to your entry and change the slug field i.imgur.com/jVeyTjq.png I don't see any problem here Jan 30, 2018 at 11:05

1 Answer 1

1

To give this an answer, the URI can be set on a per-site basis, so it is simply a matter of setting the URI for the English site to about-us and the URI for the Dutch site to over-ons on the section's settings page.

Then in your template, assuming you have the entry, you can fetch the entry in any other site and output its URL:

{% set dutchEntry = craft.entries.id(entry.id).site('dutch').one() %}
{% if dutchEntry %}
    <a href="{{ dutchEntry.url }}">Dutch</a>
{% endif %}
2
  • How do you translate this in the twig templates? Lets say <a href="{{ url('about-us') }}" when you want the dutch variant?
    – Kevon
    Sep 23, 2021 at 13:11
  • Assuming you have the entry, you can just fetch the dutch entry and output its URL. I updated my answer with the code for this.
    – Ben Croker
    Sep 28, 2021 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.