How to localize content items? - Orchard Nuggets

Zoltán Lehóczky's avatar
Localization, Orchard Nuggets, Culture picker on the Setup page, CodeMirror editor for TextField - This week in Orchard (28/03/2020)

So you want to create an Orchard Core website that presents its content in multiple languages. There are many parts of this, but what about content items? How do you make them ready for localization?

We'll assume that you have your site already set up. We'll use the Page content type found in e.g. the Agency setup recipe as an example.

  1. First, make sure that you've set up available site cultures on the Orchard dashboard. This is under Configuration, Settings, Cultures (or the /Admin/Settings/localization URL).
  2. Set up LocalizationPart for content types to be localized as mentioned in the docs.
  3. Now comes the hard part: You need content items' URLs to be generated with the culture in it, so something like "en-US/demo". This is so you can have two versions of a content item, in different languages but with the same slug ("demo"). So, edit the settings of the Autoroute part from under the content type's editor under the Content menu on the admin, Content Definition, Content Types. For the Page type it's here: /Admin/ContentTypes/Page/ContentParts/AutoroutePart/Edit. There you need to change the default Autoroute pattern to include the culture's ID. This you can do by accessing the culture set in LocalizationPart, so the whole pattern will be something like this: {{ Model.ContentItem.Content.LocalizationPart.Culture }}/{{ Model.ContentItem | display_text | slugify }}.
  4. That's pretty much it. Now when you create a new Page you'll be able to tell Orchard which culture it belongs to and the URL will automatically reflect that.

This is of course not the complete localization story. You'll also need to display the culture options to the user which you can do with the ContentCulturePicker shape as explained here. Other UI labels coming from code need to be localized too with PO files, as you can read about in the docs too. Have fun with your multi-language sites!

We also have a follow-up post on how to add a culture URL segment for non-content pages.

This post is part of our Orchard Nuggets series where we answer common Orchard questions, be it about user-facing features or developer-level issues. Check out the other posts for more such bite-sized Orchard tips and let us know if you'd have another question!


  • Daniel Pazos said Reply

    I followed all the steps you mentioned in your post but when I create a new Content Item with my default language (es-ES) the Permalink is something like this: "es-ES/Contact"

    But when I select another culture form the ones I specified in Configuration -> Settings -> Cultures, the new URL is "es-ES/Contact-0" even when the culture is "en-US".

    Am I missing something? Is the LocalizationPart not related with the cultures specified in Settings?

    Hope you can help me! Thanks in advance

  • kgwadu said Reply

    I'm having the same issue as stated by the first comment made on this page. The culture in the generated autoroute path is supposed to be the culture of the language you are editing i.e. if i edit the contact us page for example and then i use the culture picker to switch to the Japanese version of that page, when i publish i expect to see the autoroute path to be ja-JP/contact-us, instead the path is en-NZ/contact-us-0, the same culture as the English version.

    What is causing this to occur? I am having tremendous difficulty in finding any information on this.

  • Zoltán Lehóczky said Reply

    This is because when a new localized version of the content item is created then it'll be a clone of the original one, including the permalink. However, the first time you edit the newly created localized version and clear the Permalink field it'll be auto-generated on save with the correct settings.

    If you think the Permalink should rather be generated anew when the localized version is created then please open a feature request here: (Note that the first item you create will properly auto-populate Permalink.)

Add a Comment