Ticket #2282: urlify-i18n-patch.diff

File urlify-i18n-patch.diff, 3.2 KB (added by David Larlet, 9 years ago)

from http://groups.google.com/group/django-users/browse_thread/thread/6942f87bed76a536/71becdf794a900ab?lnk=gst&q=urlify.js&rnum=1#71becdf794a900ab

  • django/contrib/admin/media/js/urlify.js

     
     1function replAccents(s)
     2{
     3    // Replacement lists based on article in Wikipedia,
     4    // http://en.wikipedia.org/wiki/Latin_Unicode
     5    // from and to strings must have same number of characters
     6    var from = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîï';
     7    var to   = 'AAAAAAECEEEEIIIIDNOOOOOOUUUUYSaaaaaaaceeeeiiii';
     8    from += 'ñòóôõöøùúûüýÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģ';
     9    to   += 'noooooouuuuyyaaaaaaccccccccddddeeeeeeeeeegggggggg';
     10    from += 'ĤĥĦħĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘř';
     11    to   += 'hhhhiiiiiiiiiijjkkkllllllllllnnnnnnnnnoooooooorrrrrr';
     12    from += 'ŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƂƃƄƅƇƈƉƊƐƑƒƓƔ';
     13    to   += 'ssssssssttttttuuuuuuuuuuuuwwyyyzzzzzzfbbbbbccddeffgv';
     14    from += 'ƖƗƘƙƚƝƞƟƠƤƦƫƬƭƮƯưƱƲƳƴƵƶǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩ';
     15    to   += 'likklnnoopettttuuuuyyzzaaiioouuuuuuuuuueaaaaeeggggkk';
     16    from += 'ǪǫǬǭǰǴǵǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȞȟȤȥȦȧȨȩ';
     17    to   += 'oooojggpnnaaeeooaaaaeeeeiiiioooorrrruuuusstthhzzaaee';
     18    from += 'ȪȫȬȭȮȯȰȱȲȳḀḁḂḃḄḅḆḇḈḉḊḋḌḍḎḏḐḑḒḓḔḕḖḗḘḙḚḛḜḝḞḟḠḡḢḣḤḥḦḧḨḩḪḫ';
     19    to   += 'ooooooooyyaabbbbbbccddddddddddeeeeeeeeeeffgghhhhhhhhhh';
     20    from += 'ḬḭḮḯḰḱḲḳḴḵḶḷḸḹḺḻḼḽḾḿṀṁṂṃṄṅṆṇṈṉṊṋṌṍṎṏṐṑṒṓṔṕṖṗṘṙṚṛṜṝṞṟ';
     21    to   += 'iiiikkkkkkllllllllmmmmmmnnnnnnnnoooooooopppprrrrrrrr';
     22    from += 'ṠṡṢṣṤṥṦṧṨṩṪṫṬṭṮṯṰṱṲṳṴṵṶṷṸṹṺṻṼṽṾṿẀẁẂẃẄẅẆẇẈẉẊẋẌẍẎẏẐẑẒẓẔẕ';
     23    to   += 'ssssssssssttttttttuuuuuuuuuuvvvvwwwwwwwwwwxxxxxyzzzzzz';
     24    from += 'ẖẗẘẙẚẛẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊị';
     25    to   += 'htwyafaaaaaaaaaaaaaaaaaaaaaaaaeeeeeeeeeeeeeeeeiiii';
     26    from += 'ỌọỎỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹ';
     27    to   += 'oooooooooooooooooooooooouuuuuuuuuuuuuuyyyyyyyy';
     28
     29    for (var i = 0; i != s.length; i++) {
     30        var x = from.indexOf(s[i]);
     31        if (x != -1) {
     32            r = new RegExp(from[x], 'g');
     33            s = s.replace(r, to[x]);
     34        }
     35    }
     36    return s;
     37}
     38
    139function URLify(s, num_chars) {
     40    s = replAccents(s);
    241    // changes, e.g., "Petty theft" to "petty_theft"
    342    // remove all these words from the string before urlifying
    443    removelist = ["a", "an", "as", "at", "before", "but", "by", "for", "from",
Back to Top