Before Vorto renders the list of languages, it fires an event to allow you to filter the list or in your case, you could sort the list too. To do this, create an application event handler (http://our.umbraco.org/Documentation/Reference/Events/application-startup) and then create a handler like:
Vorto.FilterLanguages += (src, args) {
// Do something with args.Languages
}
So within the handler, you get an args object which contains the list of languages. Do whatever you want to that list, and set it back on the args object and then Vorto will use that list as the dropdown source.
Like I mentioned, the e parameter passed into your event handler has a .Languages property of type List<Language> on it which contains all the languages it's about to render. You can modify that list (sort it, or remove / add items etc) however you wish. But basically, whatever state that .Languages property is in after the event handler is run is what Vorto will use when rendering the languages list. So if you've sorted them, they will be sorted.
so it would be something like this, or is this completely off, i totally in the dark? And there dosnt seem to be any possibility of Sorting, after e.Lauguages.
Well, you can use Linq to do the sorting. Be sure to add a using statement of
using System.Linq; at the top of your class then you should be able to do something like the following in your handler:
If you don't know much about Linq, I'd really suggest you dive a little deeper into it as you'll really end up using it a lot with the strongly typed MVC stuff in Umbraco (it's a bit too broad a subject to cover in this post though).
Regarding the primary selected language, this is based upon the editors culture (set on the user admin page). Vorto will try to find the best matching language for the editors preferred culture which I'm assuming your admin user is setup as "en" or "en-GB".
Again, you can override the "default" language behaviour by setting the .IsDefault flag of one of the languages in the .Languages collection in your filter event handler. If one isn't set after the event handler is fired, Vorto will attempt to find the best match based upon the editors culture.
Yea, if it's per user you want, Id probably use the editors culture to control it. But regarding your code example, you are close, but not quite right. In linq .Where returns multiple results, where as we only want one, so you'd be better off using .First instead, so something like this should work.
(Bare in mind, if there is no language with IsoCode "da-DK" you'll get an error, so you'll either need to make sure one always exists, or use .FirstOrDefault and perform a null check instead).
var lang = e.Languages.FirstOrDefault(x => x.IsoCode == "da-DK");
if(lang != null) {
lang.IsDefault = true;
}
That's not currently possible, however I will look to add it as an option on the next build. The reason for adding it as a dropdown was that after 4 or 5 languages, you quickly run out of space so the dropdown was the best option.
Many thanks
Matt
PS If you have any other questions, feel free to ask, but I'd recommend adding them as a new forum topic, rather than tacking them on the end of other peoples questions. The main reason being, if anyone else has the same question, they won't easily be able to find yours if it's buried in another, unrelated question.
Language order
Is there a way i control the order of the languages, when the appear on a datatype?
The list, where you also have 'sync all'
Hi Peter,
Before Vorto renders the list of languages, it fires an event to allow you to filter the list or in your case, you could sort the list too. To do this, create an application event handler (http://our.umbraco.org/Documentation/Reference/Events/application-startup) and then create a handler like:
So within the handler, you get an args object which contains the list of languages. Do whatever you want to that list, and set it back on the args object and then Vorto will use that list as the dropdown source.
Hope this helps.
Many thanks
Matt
HI,
Something like this? But then what?
Hi Peter,
Like I mentioned, the
e
parameter passed into your event handler has a.Languages
property of typeList<Language>
on it which contains all the languages it's about to render. You can modify that list (sort it, or remove / add items etc) however you wish. But basically, whatever state that.Languages
property is in after the event handler is run is what Vorto will use when rendering the languages list. So if you've sorted them, they will be sorted.Many thanks
Matt
so it would be something like this, or is this completely off, i totally in the dark? And there dosnt seem to be any possibility of Sorting, after e.Lauguages.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Vorto.FilterLanguages += Document_Filter;
}
private void Document_Filter(object sender, FilterLanguagesEventArgs e)
{
e.Languages.
}
Hi Peter,
Well, you can use Linq to do the sorting. Be sure to add a using statement of
using System.Linq;
at the top of your class then you should be able to do something like the following in your handler:If you don't know much about Linq, I'd really suggest you dive a little deeper into it as you'll really end up using it a lot with the strongly typed MVC stuff in Umbraco (it's a bit too broad a subject to cover in this post though).
Hope this helps
Matt
Hi,
Thanks, It only seems to work on version 1.2
It now sort the languages correctly, but it always starts with the Uk input field, anyway to overrule that?:
And here is the code, if someone else needs it, Remeber only on Vorto vers. 1.2
using Umbraco.Core;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.web;
using System.Collections;
using Our.Umbraco.Vorto;
using System.Linq;
namespace Umbraco.Extensions.EventHandlers
{
publicclassRegisterEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Vorto.FilterLanguages += Document_Filter;
}
private void Document_Filter(object sender, Our.Umbraco.Vorto.FilterLanguagesEventArgs e)
{
e.Languages = e.Languages.OrderBy(x => x.Name).ToList();
}
}
}
Ahh yes, sorry, that was only added in 1.2 (it mentions it in the release notes http://our.umbraco.org/projects/backoffice-extensions/vorto)
Regarding the primary selected language, this is based upon the editors culture (set on the user admin page). Vorto will try to find the best matching language for the editors preferred culture which I'm assuming your admin user is setup as "en" or "en-GB".
Again, you can override the "default" language behaviour by setting the
.IsDefault
flag of one of the languages in the.Languages
collection in your filter event handler. If one isn't set after the event handler is fired, Vorto will attempt to find the best match based upon the editors culture.Many thanks
Matt
Hi,
Sorry for all these questions.
Can you elaborate a little on how to add .IsDefault
Something like this, before the filtering???
On the other hand it might be best to define it per user.
Thanks for all your help.
Hi Peter,
Yea, if it's per user you want, Id probably use the editors culture to control it. But regarding your code example, you are close, but not quite right. In linq
.Where
returns multiple results, where as we only want one, so you'd be better off using.First
instead, so something like this should work.(Bare in mind, if there is no language with IsoCode "da-DK" you'll get an error, so you'll either need to make sure one always exists, or use
.FirstOrDefault
and perform a null check instead).Many thanks
Matt
Thank you once more.
How can I get all of my languages allways be pinned on the data type whenever I open a document type
(so that I dont have to pin them on from the dropdown list everytime) ?
..to be displayed just like that - allways when I open a document type.
Thanks.
Alexander
Hi Alexander,
That's not currently possible, however I will look to add it as an option on the next build. The reason for adding it as a dropdown was that after 4 or 5 languages, you quickly run out of space so the dropdown was the best option.
Many thanks
Matt
PS If you have any other questions, feel free to ask, but I'd recommend adding them as a new forum topic, rather than tacking them on the end of other peoples questions. The main reason being, if anyone else has the same question, they won't easily be able to find yours if it's buried in another, unrelated question.
is working on a reply...