Reading names from url in different languages
# help-with-other
b
Hi all, I'm working on a feature in which I can find a certain item based on its URL, the site is in multiple languages and one of those is german. Since the german language uses the umlaut, which is parsed in an url, I can't match the correct string. For example: I'm trying to match a string "für Umbraco" In my url I'll have: mysite.com/fuer-umbraco Does anyone know how I can parse the string from the query to convert "ue" to "ü". All I've been able to find is to manually check some characters, which is ugly in my opinion.
j
If you inject IShortStringHelper, then you can do
Copy code
csharp
"für Umbraco".ToUrlSegment(_shortStringHelper) == urlSegment
That method converts your string into a urlsafe string, and is the exact same method Umbraco uses to convert names to urls, so should be a safe match. Of course it does some data handling, so "für Umbraco" "für-Umbraco" "für umbraco" may all end up as the same url string, but assuming you are fine with that based on the use case
So basically by the time you have a url segment it already has some amount of data loss, so converting back is not possible. But you can convert your other string to see if it converts to the same url segment, and if you are fine with the small inconsistencies that could be converted to the same url segment, then that would be a way to match the strings.
b
This works great! Thanks a lot
4 Views