In this tutorial, you will learn how to access multi-language data in your controllers using Vorto. When it comes to building a multi-language website within V7 you only have two main options on how you will architect your Umbraco website. Which option you pick will be based on how the content is structured.

In one approach, you create separate sub-sitewithin the Umbraco page-tree for each different language.  If your website has a different page structure for each different language, this approach makes sense.  If the content of your website follows the same page hierarchy and content structure, creating loads of subsites and copying loads of content is painful and takes forever.  If your site structure is the same regardless of language, then a better approach is to use Vorto. 

What Is Vorto?

Vorto is a Umbraco package that allows content editors to manage multi-language switching on a per property basis. 

One issue with Vorto is that it's not part of the core product.  If you use Vorto with the Umbraco Model binder and you also want to do some additional work with the data entered within Umbraco before the page is rendered, then you are going to need to write some code.  Keep reading to find out how.

How Can I Use Vorto Within A Controller

When you create a property using Vorto within Umbraco and generate a strongly typed class, out of the box Umbraco will generate a property of type Our.Umbraco.Vorto.Models.VortoValue. 

If you look at the class you'll see that it uses a collection of key-value pairs to store its data. If you want, you can manually get the data out of Vorto yourself - read this information to see how - luckily there is an easier way to work with it, namely using property value converters to make the property return the correct type.  Thanks to Dave Woestenborghs for pointing this out to me :)

If you look at the code Umbraco generates, you will see that all the classes are partial.  In the example below, let's say I've got a page-type with a property called 'sections'. 'Sections data-type is a Vorto property that nests a content data-type.  The model Umbraco will generate will look like this:

As I've mentioned working with VortoValue is kind of a pain.  It will be much easier to work with the underlining IEnumerable instead.

Instead, you can write some code to do it yourself.  If you create a new class, name it the same as the document type and ensure you use the partial modifier, it will magically hook-up and be available whenever you access your Model.

You can then create a property implementing the 'ImplementPropertyType' attribute and using the Vorto extension method, GetVortoValue().  In your code, you will now magically get the correct values for the correct language.  This approach is a lot easier and nicer than manually having to serialize and deserialize things yourself, so I recommend you give it a go.