Copied to clipboard

Flag this post as spam?

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


  • Nirmit 24 posts 97 karma points
    Jan 27, 2015 @ 01:50
    Nirmit
    0

    Fallback to default lnguage in Vorto

    Hi,
    First of all, thanks for providing this fantastic package.
    I am converting my non-umbraco single-language site into multi-language umbraco site. So to starts with I have only English content. Is there any way in Vorto to fallback the language to default language if selected language/culture is not configured for a given property? (e.g., If user has selected 'Spanish' language and a property does not have any 'Spanish' content then return English (default) content).

    Thanks, Nirmit

  • Patrick Scott 70 posts 110 karma points c-trib
    Feb 24, 2015 @ 13:09
    Patrick Scott
    0

    You will have to create your own extension function for that, the one I use is:

     

     <System.Runtime.CompilerServices.Extension> _
       Public Function GetPropertyValueMultilingual(Of T As Class)(ByVal Model As Core.Models.IPublishedContent, propertyAlias As StringOptional DefaultValue As T = NothingOptional cultureName As String = ""As T
    
           Try
    
               ' if no value then default to en-GB
               Dim Content As T
    
               Content = Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(Of T)(Model, propertyAlias)
    
               If Content Is Nothing Then
                   Content = Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(Of T)(Model, propertyAlias, "en-GB")
               End If
               Return Content
    
           Catch
               Return DefaultValue
           End Try
    
       End Function

     

  • Patrick Scott 70 posts 110 karma points c-trib
    Feb 24, 2015 @ 13:18
    Patrick Scott
    0

    just noticed that I never fully implemented the function , a complete one is below.

    <System.Runtime.CompilerServices.Extension> _
    Public Function GetPropertyValueMultilingual(Of T As Class)(ByVal Model As Core.Models.IPublishedContent, propertyAlias As StringOptional DefaultValue As T = NothingOptional cultureName As String = ""As T
        Try
            ' if no value then default to en-GB
            Dim Content As T
            If cultureName = "" Then
                Content = Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(Of T)(Model, propertyAlias)
            Else
                Content = Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(Of T)(Model, propertyAlias, cultureName)
            End If
            If Content Is Nothing Then
                Content = Our.Umbraco.Vorto.Extensions.IPublishedContentExtensions.GetVortoValue(Of T)(Model, propertyAlias, "en-GB")
            End If
            If Content Is Nothing Then
                Return DefaultValue
            Else
                Return Content
            End If
        Catch
            Return DefaultValue
        End Try
    End Function
    
    

     

  • Nirmit 24 posts 97 karma points
    Feb 26, 2015 @ 23:36
    Nirmit
    0

    Thanks Patrick, I ended up with similar approach. I wrote my own extension to fallback to supplied default language. However my code is in C#.

    Thanks for your input.

    just for reference, my version of the extension:

    public static class IPublishedContentExtensions
    {
        public static bool HasVortoValue(this IPublishedContent content, string propertyAlias, string cultureName = null, string defaultCultureName = null, bool recursive = false)
        {
            bool hasValue = content.HasVortoValue(propertyAlias, cultureName, recursive);
            if (!hasValue && !string.IsNullOrEmpty(defaultCultureName) && !defaultCultureName.Equals(cultureName))
                hasValue = content.HasVortoValue(propertyAlias, defaultCultureName, recursive);
            return hasValue;
        }
    
    
        public static object GetVortoValue(this IPublishedContent content, string propertyAlias, string cultureName = null, string defaultCultureName = null, bool recursive = false, object defaultValue = null)
        {
            var result = content.GetVortoValue(propertyAlias, cultureName, recursive, defaultValue);
            if (result == null && !string.IsNullOrEmpty(defaultCultureName) && !defaultCultureName.Equals(cultureName))
                result = content.GetVortoValue(propertyAlias, defaultCultureName, recursive, defaultValue);
    
            return result;
        }
    }
    
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Mar 25, 2015 @ 08:22
    Matt Brailsford
    100

    Hey Guys,

    Just to let you know, I've added fallback culture name support into the latest 1.4 release.

    Thanks for the feedback.

    Matt

  • AvihayBit 149 posts 303 karma points
    Jul 29, 2015 @ 10:58
    AvihayBit
    0

    Hey Matt,

    Thanks for this update - but there is no way to do it the whole website? do I have to add a language name to every Model.Content.GetVortoValue("leftColContent")?

    I think that most of the developers prefer this behavior by default so the page would have any content until we get it translated. Its good for multilingual users... Maybe an option to define a fallback language at the data-type would be a good solution.

    Its a really great package BTW. I think that this feature and a dynamics support would make it perfect ;-)

    Are you planning any new release soon?

    Thanks!

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 06, 2016 @ 14:25
    bob baty-barr
    0

    Matt, can you point to an example for the fallback functionality? thanks to expand upon this... i have english and spanish, and when i visit the site, all the links are to /es links... i would love them to be /en links... thanks

  • bh 444 posts 1544 karma points
    May 30, 2019 @ 20:03
    bh
    0

    @MattBrailsford any chance you could take a look at this Vorto related question? https://our.umbraco.com/forum/using-umbraco-and-getting-started/97531-how-to-change-my-currentuiculture

  • Nirmit 24 posts 97 karma points
    Mar 25, 2015 @ 23:47
    Nirmit
    0

    Thanks Matt. Much appriciated. I dont have to maintain a custom code now.

  • Amir Khan 1287 posts 2744 karma points
    Oct 16, 2015 @ 20:07
    Amir Khan
    0

    Hi, How do you set / retrieve the fallback language?

  • Nirmit 24 posts 97 karma points
    Oct 19, 2015 @ 06:09
    Nirmit
    0

    I have English as hard-coded default/fallback language. But if want to make it configurable, you can configure in one of your top-level node (as a property which you can retrieve in your master template). In my content-architecture, I kept one 'settings' node under which I put site-specific configuration and I populate that node in my master-template so that I can use it in anywhere in views.

    Alternatively, if you have only one default language per application then you can leverage on web.config as well.

    Hope this will be helpful.

    Regards,
    Nirmit

  • Amir Khan 1287 posts 2744 karma points
    Jul 06, 2016 @ 14:47
    Amir Khan
    0

    For anyone who is still looking for this, here's what worked for me for a grid editor data type.

    @if (Model.Content.HasVortoValue("grid") && Model.Content.GetVortoValue("grid").ToString().Length >= 120) { @Html.Partial("Grid/Standard",Model.Content.GetVortoValue("grid")) } else { @Html.Partial("Grid/Standard", Model.Content.GetVortoValue("grid", "en")) }

  • MrFlo 159 posts 403 karma points
    Nov 18, 2016 @ 08:48
    MrFlo
    0

    I was looking to show any available languages as a fallback with the chosen default language first then the others.

    So I have created this simple extension method that might be useful for someone:

    public static class IPublishedContentExtentions
    {
      public static object GetVortoValueFallback(this IPublishedContent content, string propertyAlias, string cultureName = null)
      {
            if(cultureName==null)
                cultureName = Thread.CurrentThread.CurrentUICulture.Name;
            string defaultLanguage = "en-GB";
            if (!content.HasVortoValue(propertyAlias,cultureName,fallbackCultureName: defaultLanguage))
            {
                var v = new VortoApiController();
                var languages = ((List<Our.Umbraco.Vorto.Models.Language>)v.GetInstalledLanguages()).Where(x=>x.IsoCode != cultureName && x.IsoCode != defaultLanguage);
    
                foreach (var lang in languages)
                {
                    if (content.HasVortoValue(propertyAlias, cultureName: lang.IsoCode))
                    {
                        return content.GetVortoValue(propertyAlias, lang.IsoCode);
                    }
                }
            }
    
            return content.GetVortoValue(propertyAlias, cultureName, fallbackCultureName: defaultLanguage);
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft