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 to share