Skip to content

Commit

Permalink
Support explicit culture addition in outbound routing
Browse files Browse the repository at this point in the history
  • Loading branch information
ogaudefroy committed Sep 12, 2016
1 parent d13bc23 commit 86259b7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ protected override void InitializeCulture() {
// Classical way
RouteTable.Routes.GetVirtualPath(null, "OfferDetails", new RouteValueDictionary() {{"title", "chef-de-projet"}, {"id", 12}}).VirtualPath

// With explicit culture
RouteTable.Routes.GetVirtualPath(null, "OfferDetails", new RouteValueDictionary() {{"title", "chef-de-projet"}, {"id", 12}, {"id", "fr-FR"}).VirtualPath

// Through RouteUrlExpressionBuilder
<asp:HyperLink runat="server" NavigateUrl="<%$RouteUrl:title=chef-de-projet,id=12,routename=OfferDetails%>" Text="Details" />
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void LocalizationRouteCollection_RemoveTranslation_NonExistingCulture_Thr
}

[Test]
public void LocalizationRouteCollection_OutboundRouteTest()
public void LocalizationRouteCollection_OutboundRoute_CultureInThreadTest()
{
var localizedRoute = CreateLocalizedRoute();
localizedRoute.AddTranslation(LocalizationRouteCollection.NeutralCulture, "neutral/neutral-{title}_{id}");
Expand All @@ -145,6 +145,28 @@ public void LocalizationRouteCollection_OutboundRouteTest()
tester.WithRouteInfo("OfferDetails", new { title = "project-manager", id = 12 })
.ShouldGenerateUrl("/neutral/neutral-project-manager_12");
}

}

[Test]
public void LocalizationRouteCollection_OutboundRoute_CultureInRouteValuesTest()
{
var localizedRoute = CreateLocalizedRoute();
localizedRoute.AddTranslation(LocalizationRouteCollection.NeutralCulture, "neutral/neutral-{title}_{id}");
localizedRoute.AddTranslation("en-US", "job/job-{title}_{id}");
localizedRoute.AddTranslation("fr-FR", "offre-de-emploi/offre-{title}_{id}");

var routes = new RouteCollection();
routes.Add("OfferDetails", localizedRoute);

var tester = new RouteTester(routes);

tester.WithRouteInfo("OfferDetails", new { title = "project-manager", id = 12, culture = "en-US" })
.ShouldGenerateUrl("/job/job-project-manager_12");
tester.WithRouteInfo("OfferDetails", new { title = "chef-de-projet", id = 12, culture = "fr-FR" })
.ShouldGenerateUrl("/offre-de-emploi/offre-chef-de-projet_12");
tester.WithRouteInfo("OfferDetails", new { title = "project-manager", id = 12, culture = "nl-NL" })
.ShouldGenerateUrl("/neutral/neutral-project-manager_12");
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion RouteLocalization.WebForms/LocalizationRouteCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public override VirtualPathData GetVirtualPath(RequestContext requestContext, Ro
throw new ArgumentNullException("values");
}

string currentCulture = Thread.CurrentThread.CurrentUICulture.Name;
string currentCulture = values["culture"] as string ?? Thread.CurrentThread.CurrentUICulture.Name;
var localizationRoute = this.GetLocalizedOrDefaultRoute(currentCulture);
if (localizationRoute == null)
{
Expand Down
3 changes: 2 additions & 1 deletion RouteLocalization.WebForms/RouteLocalization.WebForms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<projectUrl>https://github.com/ogaudefroy/RouteLocalization.WebForms</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ASP.Net localized routing for WebForms routes</description>
<releaseNotes></releaseNotes>
<releaseNotes>-v0.1.0: Initial Release
-v0.1.1: Support explicit culture addition in outbound routing</releaseNotes>
<copyright>$copyright$</copyright>
</metadata>
</package>

0 comments on commit 86259b7

Please sign in to comment.