Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parameterize/transliterate in Javascript?

In Ruby on Rails you can easily convert "any" text into a format which would work for subdomains/pathnames.

1) "I am nobody." -> "i-am-nobody"
2) "Grünkohl is a german word." -> "grunkohl-is-a-german-word"

I'd like to do this on the client-side for high responsiveness (alternative would be via Ajax).

The last example is called transliteration (converting Umlauts and other non-latin alphabets letters into latin ones). Transliteration would be a nice2have feature (in such cases I could fallback to Ajax to let Iconv do it).

Anybody knows how to do this with JavaScript? My current code works fine but has issues with multiple blank spaces, and Tête-à-tête becomes Tte--tte which is just ugly.

like image 275
Marcel Jackwerth Avatar asked Jan 18 '26 06:01

Marcel Jackwerth


1 Answers

When I needed this I used the Django javascript implementation for this wich covers most of this and even more :)

It can be found here: https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/static/admin/js/urlify.js

like image 58
fijter Avatar answered Jan 20 '26 20:01

fijter