2007-07-04 20:31:19 +08:00
|
|
|
|
var LATIN_MAP = {
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', 'Ç':
|
|
|
|
|
'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I',
|
|
|
|
|
'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Õ': 'O', 'Ö':
|
2007-07-12 22:00:13 +08:00
|
|
|
|
'O', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U', 'Ü': 'U', 'Ű': 'U',
|
|
|
|
|
'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à':'a', 'á':'a', 'â': 'a', 'ã': 'a', 'ä':
|
|
|
|
|
'a', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e',
|
|
|
|
|
'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', 'ð': 'o', 'ñ': 'n', 'ò': 'o', 'ó':
|
|
|
|
|
'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u',
|
|
|
|
|
'û': 'u', 'ü': 'u', 'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
}
|
2007-07-04 20:25:43 +08:00
|
|
|
|
var LATIN_SYMBOLS_MAP = {
|
|
|
|
|
'©':'(c)'
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
}
|
2007-07-04 20:31:19 +08:00
|
|
|
|
var GREEK_MAP = {
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
'α':'a', 'β':'b', 'γ':'g', 'δ':'d', 'ε':'e', 'ζ':'z', 'η':'h', 'θ':'8',
|
|
|
|
|
'ι':'i', 'κ':'k', 'λ':'l', 'μ':'m', 'ν':'n', 'ξ':'3', 'ο':'o', 'π':'p',
|
|
|
|
|
'ρ':'r', 'σ':'s', 'τ':'t', 'υ':'y', 'φ':'f', 'χ':'x', 'ψ':'ps', 'ω':'w',
|
|
|
|
|
'ά':'a', 'έ':'e', 'ί':'i', 'ό':'o', 'ύ':'y', 'ή':'h', 'ώ':'w', 'ς':'s',
|
|
|
|
|
'ϊ':'i', 'ΰ':'y', 'ϋ':'y', 'ΐ':'i',
|
|
|
|
|
'Α':'A', 'Β':'B', 'Γ':'G', 'Δ':'D', 'Ε':'E', 'Ζ':'Z', 'Η':'H', 'Θ':'8',
|
|
|
|
|
'Ι':'I', 'Κ':'K', 'Λ':'L', 'Μ':'M', 'Ν':'N', 'Ξ':'3', 'Ο':'O', 'Π':'P',
|
|
|
|
|
'Ρ':'R', 'Σ':'S', 'Τ':'T', 'Υ':'Y', 'Φ':'F', 'Χ':'X', 'Ψ':'PS', 'Ω':'W',
|
|
|
|
|
'Ά':'A', 'Έ':'E', 'Ί':'I', 'Ό':'O', 'Ύ':'Y', 'Ή':'H', 'Ώ':'W', 'Ϊ':'I',
|
|
|
|
|
'Ϋ':'Y'
|
|
|
|
|
}
|
|
|
|
|
var TURKISH_MAP = {
|
|
|
|
|
'ş':'s', 'Ş':'S', 'ı':'i', 'İ':'I', 'ç':'c', 'Ç':'C', 'ü':'u', 'Ü':'U',
|
2007-07-04 20:25:43 +08:00
|
|
|
|
'ö':'o', 'Ö':'O', 'ğ':'g', 'Ğ':'G'
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
}
|
2007-07-04 20:31:19 +08:00
|
|
|
|
var RUSSIAN_MAP = {
|
|
|
|
|
'а':'a', 'б':'b', 'в':'v', 'г':'g', 'д':'d', 'е':'e', 'ё':'yo', 'ж':'zh',
|
|
|
|
|
'з':'z', 'и':'i', 'й':'j', 'к':'k', 'л':'l', 'м':'m', 'н':'n', 'о':'o',
|
|
|
|
|
'п':'p', 'р':'r', 'с':'s', 'т':'t', 'у':'u', 'ф':'f', 'х':'h', 'ц':'c',
|
|
|
|
|
'ч':'ch', 'ш':'sh', 'щ':'sh', 'ъ':'', 'ы':'y', 'ь':'', 'э':'e', 'ю':'yu',
|
|
|
|
|
'я':'ya',
|
|
|
|
|
'А':'A', 'Б':'B', 'В':'V', 'Г':'G', 'Д':'D', 'Е':'E', 'Ё':'Yo', 'Ж':'Zh',
|
|
|
|
|
'З':'Z', 'И':'I', 'Й':'J', 'К':'K', 'Л':'L', 'М':'M', 'Н':'N', 'О':'O',
|
|
|
|
|
'П':'P', 'Р':'R', 'С':'S', 'Т':'T', 'У':'U', 'Ф':'F', 'Х':'H', 'Ц':'C',
|
|
|
|
|
'Ч':'Ch', 'Ш':'Sh', 'Щ':'Sh', 'Ъ':'', 'Ы':'Y', 'Ь':'', 'Э':'E', 'Ю':'Yu',
|
|
|
|
|
'Я':'Ya'
|
|
|
|
|
}
|
2007-09-14 06:42:30 +08:00
|
|
|
|
var UKRAINIAN_MAP = {
|
|
|
|
|
'Є':'Ye', 'І':'I', 'Ї':'Yi', 'Ґ':'G', 'є':'ye', 'і':'i', 'ї':'yi', 'ґ':'g'
|
|
|
|
|
}
|
2007-08-11 20:09:52 +08:00
|
|
|
|
var CZECH_MAP = {
|
|
|
|
|
'č':'c', 'ď':'d', 'ě':'e', 'ň': 'n', 'ř':'r', 'š':'s', 'ť':'t', 'ů':'u',
|
2007-10-20 17:27:12 +08:00
|
|
|
|
'ž':'z', 'Č':'C', 'Ď':'D', 'Ě':'E', 'Ň': 'N', 'Ř':'R', 'Š':'S', 'Ť':'T',
|
|
|
|
|
'Ů':'U', 'Ž':'Z'
|
2007-08-11 20:09:52 +08:00
|
|
|
|
}
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
|
2007-10-20 12:42:30 +08:00
|
|
|
|
var POLISH_MAP = {
|
|
|
|
|
'ą':'a', 'ć':'c', 'ę':'e', 'ł':'l', 'ń':'n', 'ó':'o', 'ś':'s', 'ź':'z',
|
|
|
|
|
'ż':'z', 'Ą':'A', 'Ć':'C', 'Ę':'e', 'Ł':'L', 'Ń':'N', 'Ó':'o', 'Ś':'S',
|
|
|
|
|
'Ź':'Z', 'Ż':'Z'
|
2007-10-20 17:27:12 +08:00
|
|
|
|
}
|
2007-10-20 12:42:30 +08:00
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
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
|
2007-07-04 20:31:19 +08:00
|
|
|
|
ALL_DOWNCODE_MAPS[4]=RUSSIAN_MAP
|
2007-09-14 06:42:30 +08:00
|
|
|
|
ALL_DOWNCODE_MAPS[5]=UKRAINIAN_MAP
|
|
|
|
|
ALL_DOWNCODE_MAPS[6]=CZECH_MAP
|
2007-10-20 12:42:30 +08:00
|
|
|
|
ALL_DOWNCODE_MAPS[7]=POLISH_MAP
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
|
|
|
|
|
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 = slug.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 ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
downcoded+=pieces[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
downcoded = slug;
|
|
|
|
|
}
|
|
|
|
|
return downcoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-16 12:27:41 +08:00
|
|
|
|
function URLify(s, num_chars) {
|
|
|
|
|
// changes, e.g., "Petty theft" to "petty_theft"
|
|
|
|
|
// remove all these words from the string before urlifying
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
s = downcode(s);
|
2005-10-20 12:20:52 +08:00
|
|
|
|
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",
|
2005-07-16 12:27:41 +08:00
|
|
|
|
"with"];
|
|
|
|
|
r = new RegExp('\\b(' + removelist.join('|') + ')\\b', 'gi');
|
|
|
|
|
s = s.replace(r, '');
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
// if downcode doesn't hit, the char will be stripped here
|
2007-02-17 14:14:23 +08:00
|
|
|
|
s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars
|
2005-07-16 12:27:41 +08:00
|
|
|
|
s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
|
2006-05-15 12:20:04 +08:00
|
|
|
|
s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens
|
2005-07-16 12:27:41 +08:00
|
|
|
|
s = s.toLowerCase(); // convert to lowercase
|
|
|
|
|
return s.substring(0, num_chars);// trim to first num_chars chars
|
2006-05-15 12:20:04 +08:00
|
|
|
|
}
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
|