Open Cefa68000 opened 11 years ago
Hello,
I will upload a localization project with AR to Github during this week.
There are still a few issues but it will be open for discussion.
Cheers, Miguel
Sorry for the huge delay. Here's some code that might work. I am still trying to understand the problem.
public static class AttributeRouting
{
public static void RegisterRoutes(RouteCollection routes)
{
// See http://github.com/mccalltd/AttributeRouting/wiki for more options.
// To debug routes locally using the built in ASP.NET development server, go to /routes.axd
routes.MapAttributeRoutes(config =>
{
config.AddRoutesFromAssemblyOf<DefaultController>();
config.AddTranslationProvider(GetTranslationProvider());
// Inbound request handling:
// - Don't honor URL's for other cultures.
// - Determine the culture by taking the last section of the URL's host.
// See: http://attributerouting.net/#localizing-urls
config.ConstrainTranslatedRoutesByCurrentUICulture = true;
config.CurrentUICultureResolver =
(httpContext, routeData) => httpContext.Request.Url.Host.Split('.').Last();
});
}
// Outbound URL generation:
// - Uses the CurrentUICulture of the executing thread.
// - Set the culture by reflecting upon the last section of the URL's host.
public static void SetCurrentUICulture(HttpRequest request)
{
var language = request.Url.Host.Split('.').Last();
var cultureInfo = new CultureInfo(language);
Thread.CurrentThread.CurrentUICulture = cultureInfo;
}
private static TranslationProviderBase GetTranslationProvider()
{
var provider = new FluentTranslationProvider();
provider.AddTranslations()
.ForController<DefaultController>()
.RouteUrl(x => x.About(), new Dictionary<string, string>
{
{ "es", "About-es" },
{ "fr", "About-fr" }
});
return provider;
}
public static void Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
You'll also need to do this in your global.asax:
public MvcApplication()
{
BeginRequest += (sender, args) => AttributeRouting.SetCurrentUICulture(Request);
}
The main points are:
ConstrainTranslatedRoutesByCurrentUICulture
and CurrentUICultureResolver
properties of the configuration object.CurrentUICulture
property appropriately when your application fires its BeginRequest event.If this doesn't help, please let me know.
I am wondering about a problem i have couple of websites in different languages same application different bindings. The domain ends with se, fi, dk
And i would like to have different translated urls for different sites. But that does not seem possible right now if i use the fluenttranslationprovider a url for se would work on fi site and dk and thats not what i want (duplicate content and stuff)
How would i go about doing something like that because i don't have access to the request.url on application start so i dont know which url to handle. And is it even possible to change translation provider on begin request event??
Do you have any solution to my particular problem?