How to localize content items? - Orchard Nuggets

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!

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!

Send us new blog feeds

Noticed that a blog's feed is missing from the list? 

We would love to add that to the feed list, so please don't hesitate to inform us on the following e-mail adress:

crew@lombiq.com

See our privacy policy.