Msdn style address URL localization possible implementation
I am trying to come up with idea how to implement msdn like localization based on address string
http://msdn.microsoft.com/en-us/library/system.string.aspx
http://msdn.microsoft.com/ru-ru/library/system.string.aspx
I tried to find various information about ASP.NET localization, but failed to find a description of strategy that can be used to get above result.
I am not very experienced with ASP.NET and would like to get some advice on how to implement something that will result in similar paths on my website(using best possible way with least code duplication for example).
I understand that I could duplicate both files in 2 folders. or 10 files in 10 folders if i got 10 cultures. But that sounds like not the best strategy. Is there some rewrite & parameter pass going on behind or ?
Update: I ended up implementing it the following way:
for my locali开发者_如何转开发zable pages I register routes to all current cultures ( in a generic method),
for example for help.aspx
I register ru-ru/help/
and en-us/help/
routes, inside help.aspx (and other localizable pages, oop way) I analyze address string and retrieve desired language. After that I setup html contents matching the related culture provided in url.
Microsoft appear to be either rewriting the URLs, or taking advantage of custom routing in ASP.NET. They are using using the URL to determine which culture to select. They could have used a query string but the URLs would not look as good.
I'd suggest that you start by looking into ASP.NET MVC as it uses routing out of the box. Then modify the routes to match those used by MS above, before using them to apply a culture.
Where you will be hosting your application could have an impact on whether you can do similar things. If you are managing the whole server and not using shared hosting it will be easier to implement these things, especially URL rewriting. If you have to use ASP.NET 2.0 because you are in some aging corporate environment you will probably have an even more difficult time.
Valentin, try to use url routing:
1 - Add routing info to global.asax
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("cultureCrossroad", "{culture}/Library/{article}", "~/library/ArticleHost.aspx");
}
2 - Create host page at ~/Library/ArticleHost.aspx
public partial class ArticleHost : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// ! Here we have access to url's parts and can redirect user for desired page via Server.Transfer method.
var response = string.Format("culture: {0}<br/> article: {1}", Page.RouteData.Values["culture"], Page.RouteData.Values["article"]);
Response.Write(response);
}
}
精彩评论