Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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/
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;
}
}
}
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