C#: convert Unicode to use as url
I'm working on multilingual Asp.NET MVC application. In url i need to use category name. Is there any way how to convert i.e japanese text to its url safe equivalent? Or should i use original text in url(www.example.com/製品/車 = www.example.com/product/car)?
EDIT: I need SEO firenly urls. I know how to strip diacritics and replace spaces(or other special characters) with '-'. Bu开发者_如何学Pythont i wonder how to deal with foreign languages like Japanese, Russian etc.
It depends on how you are generating the url but you could use the UrlEncode method.
If you think a crawler could guess the product names or categories correctly to land on all pages of your site, it would be just as likely to do so with a number. Use the name or category ID, saves you the hassle from localizing these names as well.
You could UrlEncode the path elements, but the result will be illegible for the human eye (and probably search engines as well). Translating the elements to English or romanizing them sounds like a good idea. You need a dictionary though:
var comparer = StringComparer.Create(new CultureInfo("ja-JP"), false);
var dict = new Dictionary<string, string>(comparer)
{
{ "", "" },
{ "製品", "product" },
{ "車", "car" },
};
var path = "/製品/車";
var translatedPath = string.Join("/", path.Split('/').Select(s => dict[s]));
精彩评论