Copied to clipboard

Flag this post as spam?

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


  • Claudio Ridolfi 11 posts 62 karma points
    Jun 30, 2015 @ 20:24
    Claudio Ridolfi
    0

    adding language to internal links in rte

    Hi again, i have a website running with 2 different languages, the problem is when I add internal links to content in RTE: when the page is rendered in the links are missing the language part, so every time one click it fall back to the main language. Am I doing something wrong?

  • Arturo Soler 24 posts 77 karma points
    Jul 02, 2015 @ 08:39
    Arturo Soler
    0

    Are you using the propertyTranslation Macro?

  • Claudio Ridolfi 11 posts 62 karma points
    Jul 02, 2015 @ 11:20
    Claudio Ridolfi
    0

    I'm using a modified version of PropertyTranslation to render grids (I posted the code in a previous topic here), but as the original PropertyTranslation the renderer used by GetGridHtml calls TemplateUtilities.ParseInternalLinks. The internal links are rendered, but without the add of the currently selected language, that's why it falls back to the main language of the site

  • Arturo Soler 24 posts 77 karma points
    Jul 03, 2015 @ 08:17
    Arturo Soler
    0

    Excuse me, I was not related to your previous post. Unfortunately I have no experience with grids. Since yesterday was a bit more but certainly less than you. If I find something next week I tell (this was my week vacation)

  • dimi309 245 posts 579 karma points
    Jul 06, 2015 @ 20:13
    dimi309
    0

    If you are entering the URLs yourself, then you would also need to add the corresponding language parameter, e.g. http://some.link/page?lang=en

  • Claudio Ridolfi 11 posts 62 karma points
    Jul 07, 2015 @ 08:08
    Claudio Ridolfi
    0

    Ok, so there's no way to have the language automatically added when selecting link using the content tree?

  • dimi309 245 posts 579 karma points
    Jul 07, 2015 @ 18:08
    dimi309
    0

    It's a good idea for further development but, at the moment, sadly no...

  • Claudio Ridolfi 11 posts 62 karma points
    Jul 07, 2015 @ 19:10
    Claudio Ridolfi
    0

    Ok thank you! I thought I was doing something wrong! I'll try to find a solution :)

  • Arturo Soler 24 posts 77 karma points
    Jul 08, 2015 @ 08:27
    Arturo Soler
    0

    What the luck be with you !, Claudio. This week I've been looking at the grids and are really complex. Perhaps this package will be useful for you: Skybrud.Umbraco.GridData Unfortunately the only example is for read-only access , to index with Examine the RTEs within a grid.

  • Claudio Ridolfi 11 posts 62 karma points
    Jul 08, 2015 @ 15:24
    Claudio Ridolfi
    0

    Here's a quick and dirty solution (when I'll have time I'll try to make something more clean). Just replace the ParseInternalLinks with a modded version that add the current language. I made it for the grid system, but the same logic could be applied to the PropertyTranslation.

    In my case i made the change to Views\Partials\Grid\Editors\Rte.cshtml which now is:

    @model dynamic
    @using Umbraco.Web.Templates
    @using System.Text.RegularExpressions
    @using Umbraco.Web
    
    @Html.Raw(ParseInternalLinksTranslated(Model.value.ToString()))
    
    @helper ParseInternalLinksTranslated(string text){
        string selectedLanguage = RenderPage("~/macroScripts/SelectedLanguage.cshtml").ToString().Trim();
        var urlProvider = UmbracoContext.Current.UrlProvider; 
    
    
        var tags = Regex.Matches(text, @"href=""[/]?(?:\{|\%7B)localLink:([0-9]+)(?:\}|\%7D)", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); 
        foreach (Match tag in tags) 
        {
            if (tag.Groups.Count > 0) 
            { 
                var id = tag.Groups[1].Value;
                var newLink = urlProvider.GetUrl(int.Parse(id)); 
                text = text.Replace(tag.Value, "href=\"/" + selectedLanguage + newLink); 
            }  
        }
        @Html.Raw(text) 
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft