Project

General

Profile

Feature #13824 » project_identifier.js.v2.patch

Filou Centrinov, 2013-04-22 18:19

View differences:

public/javascripts/project_identifier.js (working copy)
1 1
// Automatic project identifier generation
2 2

  
3 3
function generateProjectIdentifier(identifier, maxlength) {
4
  
5
  // Latin alphabet
4 6
  var diacriticsMap = [
5 7
    {'base':'a', 'letters':/[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g},
6 8
    {'base':'aa','letters':/[\uA733\uA732]/g},
......
27 29
    {'base':'n', 'letters':/[\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4]/g},
28 30
    {'base':'nj','letters':/[\u01CC\u01CA\u01CB]/g},
29 31
    {'base':'o', 'letters':/[\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C]/g},
30
    {'base':'oe','letters': /[\u00F6\u0153\u00D6\u0152]/g},
32
    {'base':'oe','letters':/[\u00F6\u0153\u00D6\u0152]/g},
31 33
    {'base':'oi','letters':/[\u01A3\u01A2]/g},
32 34
    {'base':'ou','letters':/[\u0223\u0222]/g},
33 35
    {'base':'oo','letters':/[\uA74F\uA74E]/g},
34
    {'base':'p','letters':/[\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754]/g},
35
    {'base':'q','letters':/[\u0071\u24E0\uFF51\u024B\uA757\uA759\u0051\u24C6\uFF31\uA756\uA758\u024A]/g},
36
    {'base':'r','letters':/[\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782]/g},
37
    {'base':'s','letters':/[\u0073\u24E2\uFF53\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784]/g},
36
    {'base':'p', 'letters':/[\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754]/g},
37
    {'base':'q', 'letters':/[\u0071\u24E0\uFF51\u024B\uA757\uA759\u0051\u24C6\uFF31\uA756\uA758\u024A]/g},
38
    {'base':'r', 'letters':/[\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782]/g},
39
    {'base':'s', 'letters':/[\u0073\u24E2\uFF53\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784]/g},
38 40
    {'base':'ss','letters':/[\u00DF]/g},
39
    {'base':'t','letters':/[\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786]/g},
41
    {'base':'t', 'letters':/[\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786]/g},
40 42
    {'base':'tz','letters':/[\uA729\uA728]/g},
41
    {'base':'u','letters':/[\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244]/g},
43
    {'base':'u', 'letters':/[\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244]/g},
42 44
    {'base':'ue','letters':/[\u00FC\u00DC]/g},
43
    {'base':'v','letters':/[\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245]/g},
45
    {'base':'v', 'letters':/[\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245]/g},
44 46
    {'base':'vy','letters':/[\uA761\uA760]/g},
45
    {'base':'w','letters':/[\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72]/g},
46
    {'base':'x','letters':/[\u0078\u24E7\uFF58\u1E8B\u1E8D\u0058\u24CD\uFF38\u1E8A\u1E8C]/g},
47
    {'base':'y','letters':/[\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE]/g},
48
    {'base':'z','letters':/[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762]/g}
47
    {'base':'w', 'letters':/[\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72]/g},
48
    {'base':'x', 'letters':/[\u0078\u24E7\uFF58\u1E8B\u1E8D\u0058\u24CD\uFF38\u1E8A\u1E8C]/g},
49
    {'base':'y', 'letters':/[\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE]/g},
50
    {'base':'z', 'letters':/[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762]/g}
49 51
  ];
52
  
53
  // Greek alphabet
54
  diacriticsMap = diacriticsMap.concat([
55
    {'base':'a', 'letters':/[\u0391\u03b1]/g},
56
    {'base':'b', 'letters':/[\u0392\u03b2]/g},
57
    {'base':'ch','letters':/[\u03a7\u03c7]/g},
58
    {'base':'d', 'letters':/[\u0394\u03b4]/g},
59
    {'base':'e', 'letters':/[\u0395\u03b5\u0397\u03b7]/g},
60
    {'base':'g', 'letters':/[\u0393\u03b3]/g},
61
    {'base':'i', 'letters':/[\u0399\u03b9]/g},
62
    {'base':'k', 'letters':/[\u039a\u03ba]/g},
63
    {'base':'l', 'letters':/[\u039b\u03bb]/g},
64
    {'base':'m', 'letters':/[\u039c\u03bc]/g},
65
    {'base':'n', 'letters':/[\u039d\u03bd]/g},
66
    {'base':'o', 'letters':/[\u039f\u03bf\u03a9\u03c9]/g},
67
    {'base':'p', 'letters':/[\u03a0\u03c0]/g},
68
    {'base':'ph','letters':/[\u03a6\u03c6]/g},
69
    {'base':'ps','letters':/[\u03a8\u03c8]/g},
70
    {'base':'r', 'letters':/[\u03a1\u03c1]/g},
71
    {'base':'s', 'letters':/[\u03a3\u03c3]/g},
72
    {'base':'t', 'letters':/[\u03a4\u03c4]/g},
73
    {'base':'th','letters':/[\u0398\u03b8]/g},
74
    {'base':'x', 'letters':/[\u039e\u03be]/g},
75
    {'base':'y', 'letters':/[\u03a5\u03c5]/g},
76
    {'base':'z', 'letters':/[\u0396\u03b6]/g}
77
  ]);  
78
  
79
  // Cyrillic alphabet
80
  diacriticsMap = diacriticsMap.concat([
81
    {'base':'a', 'letters':/[\u0410\u0430\u018f\u0259]/g},
82
    {'base':'b', 'letters':/[\u0411\u0431]/g},
83
    {'base':'c', 'letters':/[\u0426\u0446]/g},
84
    {'base':'ch','letters':/[\u0427\u0447]/g},
85
    {'base':'dj','letters':/[\u0402\u0452]/g},
86
    {'base':'dz','letters':/[\u0405\u0455\u040f\u045f]/g},
87
    {'base':'e' ,'letters':/[\u0415\u0435\u042d\u044d\u0400\u0450]/g},
88
    {'base':'f' ,'letters':/[\u0424\u0444]/g},
89
    {'base':'g' ,'letters':/[\u0413\u0433\u0490\u0491\u011e\u011f]/g},
90
    {'base':'gj','letters':/[\u0403\u0453]/g},
91
    {'base':'h' ,'letters':/[\u04ba\u04bb]/g},
92
    {'base':'i' ,'letters':/[\u0418\u0438\u042b\u044b\u0406\u0456\u040d\u045d]/g},
93
    {'base':'j' ,'letters':/[\u0419\u0439]/g},
94
    {'base':'ji','letters':/[\u0407\u0457]/g},
95
    {'base':'je','letters':/[\u0404\u0454]/g},
96
    {'base':'jo','letters':/[\u0401\u0451]/g},
97
    {'base':'k' ,'letters':/[\u041a\u043a]/g},
98
    {'base':'kj','letters':/[\u040c\u045c]/g},
99
    {'base':'l' ,'letters':/[\u041b\u043b\u0512\u0513]/g},
100
    {'base':'lj','letters':/[\u0409\u0459]/g},
101
    {'base':'m' ,'letters':/[\u041c\u043c]/g},
102
    {'base':'n' ,'letters':/[\u041d\u043d]/g},
103
    {'base':'nj','letters':/[\u040a\u045a]/g},
104
    {'base':'o' ,'letters':/[\u03a9\u03c9\u041e\u043e]/g},
105
    {'base':'p' ,'letters':/[\u041f\u043f]/g},
106
    {'base':'r' ,'letters':/[\u0420\u0440]/g},
107
    {'base':'s' ,'letters':/[\u0421\u0441]/g},
108
    {'base':'sh','letters':/[\u0428\u0448]/g},
109
    {'base':'shch','letters':/[\u0429\u0449]/g},
110
    {'base':'t' ,'letters':/[\u0422\u0442]/g},
111
    {'base':'u' ,'letters':/[\u0423\u0443\u040e\u045e]/g},
112
    {'base':'v' ,'letters':/[\u0412\u0432]/g},
113
    {'base':'ya','letters':/[\u042f\u044f]/g},
114
    {'base':'yu','letters':/[\u042e\u044e]/g},
115
    {'base':'z' ,'letters':/[\u0417\u0437]/g},
116
    {'base':'zh','letters':/[\u0416\u0436]/g}
117
  ]);
118
  
50 119

  
51 120
  for(var i=0; i<diacriticsMap.length; i++) {
52 121
    identifier = identifier.replace(diacriticsMap[i].letters, diacriticsMap[i].base);
(2-2/2)