Commit 1c6ab32a5b36f613819aa99106df81cb0de3fea2

Authored by AntonioTerceiro
1 parent 5b031746

ActionItem57: generating slug transliterating utf-8 characters to ascii



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@576 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 1 changed file with 24 additions and 1 deletions   Show diff stats
public/javascripts/cms.js
... ... @@ -290,7 +290,30 @@ Object.extend(String.prototype, {
290 290 toSlug: function() {
291 291 // M@: Modified from Radiant's version, removes multple --'s next to each other
292 292 // This is the same RegExp as the one on the page model...
293   - return this.strip().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=_+]+/g, '-').replace(/[\-]{2,}/g, '-');
  293 + return this.strip().transliterate().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=_+]+/g, '-').replace(/[\-]{2,}/g, '-');
  294 + },
  295 + transliterate: function() {
  296 + var substitutions = [
  297 + { from: [ 'Á', 'À', 'À', 'Â', 'Ã', 'Ä' ], to: 'A' },
  298 + { from: [ 'á', 'à', 'à', 'â', 'ã', 'ä', 'ª' ], to: 'a' },
  299 + { from: [ 'É', 'È', 'Ê', 'Ë' ], to: 'E' },
  300 + { from: [ 'é', 'è', 'ê', 'ë' ], to: 'e' },
  301 + { from: [ 'Í', 'Ì', 'Î', 'Ï' ], to: 'I' },
  302 + { from: [ 'í', 'ì', 'î', 'ï' ], to: 'i' },
  303 + { from: [ 'Ó', 'Ò', 'Ô', 'Ö', 'Õ', 'º' ], to: 'O' },
  304 + { from: [ 'ó', 'ò', 'ô', 'ö', 'õ', 'º' ], to: 'o' },
  305 + { from: [ 'Ú', 'Ù', 'Û', 'Ü' ], to: 'U' },
  306 + { from: [ 'ú', 'ù', 'û', 'ü' ], to: 'u' },
  307 + { from: [ 'Ç' ], to: 'C' },
  308 + { from: [ 'ç' ], to: 'c' },
  309 + { from: [ 'Ñ' ], to: 'N' },
  310 + { from: [ 'ñ' ], to: 'n' },
  311 + { from: [ 'Ÿ' ], to: 'Y' },
  312 + { from: [ 'ÿ' ], to: 'y' },
  313 + ]
  314 + var res = this;
  315 + for (i in substitutions) { for (from in substitutions[i].from) { res = res.replace(substitutions[i].from[from], substitutions[i].to); } };
  316 + return res;
294 317 }
295 318 });
296 319  
... ...