views:

126

answers:

3

Hi. 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 '-'. But i wonder how to deal with foreign languages like Japanese, Russian etc.

+2  A: 

It depends on how you are generating the url but you could use the UrlEncode method.

Darin Dimitrov
IMHO, result from UrlEncode is not SEO friendly. Server.UrlEncode("á") returns "%c3%a1".
Feryt
A: 

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]));
dtb
+1  A: 

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.

Hans Passant