Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 18, 2014 @ 16:22
    Peter Cort Larsen
    1

    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'

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jun 18, 2014 @ 16:57
    Matt Brailsford
    0

    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:

    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.

    Hope this helps.

    Many thanks

    Matt

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 18, 2014 @ 22:08
    Peter Cort Larsen
    0

    HI,

    Something like this? But then what?

     



    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
    using System.Collections;
    using Our.Umbraco.Vorto;

    namespace Umbraco.Extensions.EventHandlers
    {
    public class RegisterEvents : ApplicationEventHandler
    {
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
    Vorto.FilterLanguages += Document_Filter;
    }

    private void Document_Filter(object sender, FilterLanguagesEventArgs e)
    {
    //e.Languages
    }
    }
    }
  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jun 18, 2014 @ 22:27
    Matt Brailsford
    0

    Hi Peter,

    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.

    Many thanks

    Matt

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 18, 2014 @ 22:42
    Peter Cort Larsen
    0

    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.
    }

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jun 19, 2014 @ 11:44
    Matt Brailsford
    0

    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:

    e.Languages = e.Languages.OrderBy(x => x.Name).ToList();
    

    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

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 19, 2014 @ 11:57
    Peter Cort Larsen
    0

    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?:

     

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 19, 2014 @ 11:58
    Peter Cort Larsen
    0

    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();

            }

        }

    }

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jun 19, 2014 @ 12:04
    Matt Brailsford
    101

    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

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 19, 2014 @ 12:10
    Peter Cort Larsen
    0

    Hi,

     

    Sorry for all these questions. 
    Can you elaborate a little on how to add .IsDefault 

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 19, 2014 @ 12:12
    Peter Cort Larsen
    0

    Something like this, before the filtering???

     

    e.Languages.Where(x.IsoCode == "da-DK").IsDefault = true;
  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 19, 2014 @ 12:15
    Peter Cort Larsen
    0

    On the other hand it might be best to define it per user.

     

    Thanks for all your help.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jun 19, 2014 @ 12:26
    Matt Brailsford
    1

    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.

    e.Languages.First(x => x.IsoCode == "da-DK").IsDefault = true;
    

    (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;
    }
    

    Many thanks

    Matt

  • Peter Cort Larsen 418 posts 1015 karma points
    Jun 19, 2014 @ 12:31
    Peter Cort Larsen
    0

    Thank you once more.

  • alexant 22 posts 42 karma points
    Jun 29, 2014 @ 17:36
    alexant
    0

    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

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jun 30, 2014 @ 10:14
    Matt Brailsford
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft