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!

1 Comment

  • 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

Add a Comment