I want to create a SEO friendly url, so after a few research, i come up with creating slug and do something with the router. However, it seems that the slug creator around internet only support english alphabet character. So, i need a better slug creator for my vietnamese alphabet.
Anyone got a plugin, or a suggestion for me?
Thanks in advance
You could extend an existing Slugifier to normalize the vietnamese characters.
From a similar post in the Django context:
A simple version for you case would be:
vietnamese_map = { ord(u'ư'): 'u', ord(u'ơ'): 'o', ord(u'á'): 'a', ord(u'n'): 'n', ord(u'h'): 'h', ord(u'ữ'): 'u', ord(u'n'): 'n', ord(u'g'): 'g', ord(u'v'): 'v', ord(u'i'): 'i', ord(u'ê'): 'e', ord(u'n'): 'n', ord(u'k'): 'k', ord(u'ẹ'): 'e', ord(u'o'): 'o', }
And then you can call:
print u"những-viên-kẹo".translate(vietnamese_map) To get: u"nhung-vien-keo"
But of course you'll need to write that in PHP.
If you don't want to extend the builtin slugifier, Boris Guery's Bgy_Filter_Slugify
works well for me:
https://github.com/borisguery/bgylibrary/blob/master/library/Bgy/Filter/Slugify.php
You could also extract the slugification code used by WordPress, if that still isn't robust enough for you.
EDIT:
WordPress code may already handle the conversion of accented characters into their latin equivalent.
Here for example is their remove_accents
function.