C #: Convert Unicode to use as url

I am working on ASP.NET MVC multilingual application. In url, I need to use the category name. Is there a way to convert ie Japanese text to its safe equivalent? Or should I use the original text in the url (www.example.com/ 製品 / 車 = www.example.com/product/car)?

EDIT: I want optimistic SEO URLs. I know how to remove diacritics and replace spaces (or other special characters) with "-". But I'm wondering how to work with foreign languages ​​like Japanese, Russian, etc.

+2


a source to share


3 answers


You can UrlEncode path elements, but the result will be illegible to the human eye (and probably search engines). Translating the elements into 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]));

      

0


a source


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



+2


a source


If you think the searcher could correctly guess the product or category names in order to land on all the pages on your site, it would be just as likely to do so with a number. Use a name or category ID, it also saves you the trouble of localizing those names.

+1


a source







All Articles