private IEnumerable<AttributeRoute> Build(RouteSpecification routeSpec) { var route = new AttributeRoute(CreateRouteUrl(routeSpec), CreateRouteDefaults(routeSpec), CreateRouteConstraints(routeSpec), CreateRouteDataTokens(routeSpec), _configuration) { RouteName = CreateRouteName(routeSpec), Translations = CreateRouteTranslations(routeSpec), Subdomain = routeSpec.Subdomain }; // Yield the default route first yield return route; // Then yield the translations if (route.Translations == null) yield break; foreach (var translation in route.Translations) { // Backreference the default route. translation.DefaultRoute = route; yield return translation; } }
private IEnumerable <AttributeRoute> Build(RouteSpecification routeSpec) { var route = new AttributeRoute(CreateRouteUrl(routeSpec), CreateRouteDefaults(routeSpec), CreateRouteConstraints(routeSpec), CreateRouteDataTokens(routeSpec), _configuration) { RouteName = CreateRouteName(routeSpec), Translations = CreateRouteTranslations(routeSpec), Subdomain = routeSpec.Subdomain }; // Yield the default route first yield return(route); // Then yield the translations if (route.Translations == null) { yield break; } foreach (var translation in route.Translations) { // Backreference the default route. translation.DefaultRoute = route; yield return(translation); } }
private IEnumerable <AttributeRoute> CreateRouteTranslations(RouteSpecification routeSpec) { // If no translation provider, then get out of here. if (!_configuration.TranslationProviders.Any()) { yield break; } // Merge all the culture names from the various providers. var cultureNames = _configuration.GetTranslationProviderCultureNames(); // Built the route translations, // choosing the first available translated route component from among the providers foreach (var cultureName in cultureNames) { string translatedRouteUrl = null, translatedRoutePrefix = null, translatedAreaUrl = null; foreach (var provider in _configuration.TranslationProviders) { translatedRouteUrl = translatedRouteUrl ?? provider.TranslateRouteUrl(cultureName, routeSpec); translatedRoutePrefix = translatedRoutePrefix ?? provider.TranslateRoutePrefix(cultureName, routeSpec); translatedAreaUrl = translatedAreaUrl ?? provider.TranslateAreaUrl(cultureName, routeSpec); } if (translatedRouteUrl == null && translatedRoutePrefix == null && translatedAreaUrl == null) { continue; } var translatedRoute = new AttributeRoute(CreateRouteUrl(translatedRouteUrl ?? routeSpec.RouteUrl, translatedRoutePrefix ?? routeSpec.RoutePrefixUrl, translatedAreaUrl ?? routeSpec.AreaUrl, routeSpec.IsAbsoluteUrl), CreateRouteDefaults(routeSpec), CreateRouteConstraints(routeSpec), CreateRouteDataTokens(routeSpec), _configuration) { CultureName = cultureName, }; translatedRoute.DataTokens.Add("cultureName", cultureName); yield return(translatedRoute); } }
private IEnumerable<AttributeRoute> CreateRouteTranslations(RouteSpecification routeSpec) { // If no translation provider, then get out of here. if (!_configuration.TranslationProviders.Any()) yield break; // Merge all the culture names from the various providers. var cultureNames = _configuration.GetTranslationProviderCultureNames(); // Built the route translations, // choosing the first available translated route component from among the providers foreach (var cultureName in cultureNames) { string translatedRouteUrl = null, translatedRoutePrefix = null, translatedAreaUrl = null; foreach (var provider in _configuration.TranslationProviders) { translatedRouteUrl = translatedRouteUrl ?? provider.TranslateRouteUrl(cultureName, routeSpec); translatedRoutePrefix = translatedRoutePrefix ?? provider.TranslateRoutePrefix(cultureName, routeSpec); translatedAreaUrl = translatedAreaUrl ?? provider.TranslateAreaUrl(cultureName, routeSpec); } if (translatedRouteUrl == null && translatedRoutePrefix == null && translatedAreaUrl == null) continue; var translatedRoute = new AttributeRoute(CreateRouteUrl(translatedRouteUrl ?? routeSpec.RouteUrl, translatedRoutePrefix ?? routeSpec.RoutePrefixUrl, translatedAreaUrl ?? routeSpec.AreaUrl, routeSpec.IsAbsoluteUrl), CreateRouteDefaults(routeSpec), CreateRouteConstraints(routeSpec), CreateRouteDataTokens(routeSpec), _configuration) { CultureName = cultureName, }; translatedRoute.DataTokens.Add("cultureName", cultureName); yield return translatedRoute; } }