Created
August 27, 2015 16:03
-
-
Save alindgren/a01381ef53ae55970207 to your computer and use it in GitHub Desktop.
UrlProvider for generating multilingual URLs in 1:1 multilingual Umbraco sites - see http://www.alexlindgren.com/archive/building-multilingual-sites-in-umbraco-with-vorto-part-2/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Umbraco.Web.Routing; | |
/// <summary> | |
/// MultilingualUrlProvider | |
/// </summary> | |
public class MultilingualUrlProvider : IUrlProvider | |
{ | |
public IEnumerable<string> GetOtherUrls(Umbraco.Web.UmbracoContext umbracoContext, int id, Uri current) | |
{ | |
var originalRoute = umbracoContext.ContentCache.GetRouteById(id); | |
var urls = new List<string>() | |
{ | |
"/es" + originalRoute | |
}; | |
return urls; | |
} | |
public string GetUrl(Umbraco.Web.UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode) | |
{ | |
var originalRoute = umbracoContext.ContentCache.GetRouteById(id); | |
if (umbracoContext.PublishedContentRequest != null) | |
{ | |
var culture = umbracoContext.PublishedContentRequest.Culture; | |
return "/" + culture.Name + originalRoute; | |
} | |
else | |
{ | |
return "/en-US" + originalRoute; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Core; | |
using Umbraco.Web.Routing; | |
public class RegisterEvents : ApplicationEventHandler | |
{ | |
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, MultilingualUrlProvider>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment