Malcolm Tredinnick wrote: > Personally, I was kind of hoping whoever wrote > the patch might think this sort of thing through and give us a concrete > target to throw ideas at. :-)
Hi Malcolm, Here we go: [[[urlify.js: var LATIN_MAP = { 'À':'A', 'Á':'A', 'à':'a', 'á':'a', '©':'c' } ; var LATIN_SYMBOLS_MAP = { } var GREEK_MAP = { } var TURKISH_MAP = { } var RUSSIAN_MAP = { } var ALL_DOWNCODE_MAPS=new Array() ALL_DOWNCODE_MAPS[0]=LATIN_MAP ALL_DOWNCODE_MAPS[1]=LATIN_SYMBOLS_MAP ALL_DOWNCODE_MAPS[2]=GREEK_MAP ALL_DOWNCODE_MAPS[3]=TURKISH_MAP ALL_DOWNCODE_MAPS[4]=RUSSIAN_MAP var Downcoder = new Object() ; Downcoder.Initialize = function() { if (Downcoder.map) // already made return ; Downcoder.map ={} Downcoder.chars = '' ; for(var i in ALL_DOWNCODE_MAPS) { var lookup = ALL_DOWNCODE_MAPS[i] for (var c in lookup) { Downcoder.map[c] = lookup[c] ; Downcoder.chars += c ; } } Downcoder.regex = new RegExp('[' + Downcoder.chars + ']|[^' + Downcoder.chars + ']+','g') ; } downcode= function( slug ) { Downcoder.Initialize() ; var downcoded ="" var pieces = str.match(Downcoder.regex); if(pieces) { for (var i = 0 ; i < pieces.length ; i++) { if (pieces[i].length == 1) { var mapped = Downcoder.map[pieces[i]] ; if (mapped != null) { downcoded+=mapped; continue ; } } else { downcoded+=pieces[i]; } } } else { downcoded = slug; } return downcoded; } function URLify(s, num_chars) { s = downcode(s); removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from", "is", "in", "into", "like", "of", "off", "on", "onto", "per", "since", "than", "the", "this", "that", "to", "up", "via", "with"]; r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi'); s = s.replace(r, ''); // if downcode fails, the char will be stripped here s = s.replace(/[^-A-Z0-9\s]/gi, ''); s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens s = s.toLowerCase(); // convert to lowercase return s.substring(0, num_chars);// trim to first num_chars chars return s.substring(0, num_chars);// trim to first num_chars chars } ]]] I need to test this properly and fill in the mappings, but the gist of the approach should be clear. When that's done, unless someone has an objection, I'll file a patch against http://code.djangoproject.com/ticket/1602 (also 2282) . cheers Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---