In this tutorial, you will learn how to access multi-language data in your controllers using Vorto manually. It should be noted that this approach isn't the easiest or nicest approach. - for that I recommend you check out this article - if you have some requirement where you need something slightly different than plain out of the box display the current language, then manually getting the data yourself is probably your best option
How Can I Use Vorto Within A Controller
When you create a property using Vorto on a document type and use Model Builder, it will get created as an 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.
This means that if you want to access the content you need to iterate through this collection, match the key (culture) to the pages current culture and then return the value:
Getting Data From More Complex Properties
Getting a string/single value out of Vorto is simple. If you wrap say the related links property, which contains a collection of items, things get slightly more complex when you want to get the data.
For complex properties, Vorto serializes the properties and stores all the data as JSON. If you have a complex property that you want to get data from, you will need to use Json.NET and manually deserialize the data yourself. For related links, you can create a class that mirrors all the properties within the picker:
You still get the data out of Vorto the same, however, this time you use JSON.net on the property and deserialize it.
Getting an IPublished Content Out Of A Property
When you wrap slightly more complex properties with Vorto, like nest content, content picker, you can see an Umbraco UDI being returned. In those situations, you can use this snippet (more info about Umbraco UDI here):
Now you should have the value the content editor added for that language and you are now free to do any extra processing that you need, enjoy!