mirror of
https://github.com/soulaklabs/bitoduc.fr.git
synced 2025-12-08 17:13:23 +00:00
Meilleure francisation du code
Ajout de sansAccents dans les prototypes de Chaine Renommage des fonctions à l'infinitif
This commit is contained in:
28
js/fr.js
28
js/fr.js
@@ -1,28 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var Objet = Object
|
||||
Objet.creer = Objet.create
|
||||
|
||||
var Chaine = String
|
||||
Chaine.prototype.enMinuscules = Chaine.prototype.toLowerCase
|
||||
Chaine.prototype.enMajuscules = Chaine.prototype.toUpperCase
|
||||
Chaine.prototype.remplacer = Chaine.prototype.replace
|
||||
Chaine.prototype.caractereA = Chaine.prototype.charAt
|
||||
|
||||
var Tableau = Array
|
||||
Tableau.prototype.tri = Tableau.prototype.sort
|
||||
Tableau.prototype.longueur = function () { return this.length; }
|
||||
Tableau.prototype.pousser = Tableau.prototype.push
|
||||
|
||||
document.creerElement = document.createElement
|
||||
document.recupererElementParNomDEtiquette = document.getElementsByTagName;
|
||||
document.localisation = document.location;
|
||||
document.localisation.protocole = document.localisation.protocole;
|
||||
|
||||
jQuery.fn.extend({
|
||||
clic: function (x) { return this.click(x); },
|
||||
enfants: function () { return this.children(); },
|
||||
dernier: function () { return this.last(); },
|
||||
ajouter: function (x) { return this.append(x); }
|
||||
});
|
||||
$.recupererJSON = $.getJSON
|
||||
@@ -3,16 +3,16 @@
|
||||
var reciproque = {'anglais': 'francais', 'francais': 'anglais'};
|
||||
var embelli = {'francais': 'Français', 'anglais': 'Anglais'};
|
||||
|
||||
function changeDeSens(traductions) {
|
||||
function inverser(traductions) {
|
||||
var langue = $( "#mots" ).attr("data-langue");
|
||||
$( "#mots" ).attr("data-langue", reciproque[langue]);
|
||||
construitListe(traductions);
|
||||
}
|
||||
|
||||
function metAJourLienChange(langue) {
|
||||
function mettreAJourLienInversion(langue) {
|
||||
var langueSource = langue;
|
||||
var langueDestination = reciproque[langue];
|
||||
$( "#lienChange" )
|
||||
$( "#lienInversion" )
|
||||
.html(
|
||||
'<span class="mot-' + langueSource + '">'
|
||||
+ embelli[langueSource]
|
||||
@@ -24,26 +24,6 @@ function metAJourLienChange(langue) {
|
||||
);
|
||||
}
|
||||
|
||||
function sansAccents(mot) {
|
||||
// Faute d'une bibliotheque unidecode, nous nous limitons aux lettres
|
||||
// accentuées du français.
|
||||
// https://fr.wikipedia.org/wiki/Diacritiques_utilisés_en_français
|
||||
return mot
|
||||
.enMinuscules()
|
||||
.remplacer("à", "a")
|
||||
.remplacer("â", "a")
|
||||
.remplacer("ç", "c")
|
||||
.remplacer("é", "e")
|
||||
.remplacer("è", "e")
|
||||
.remplacer("ê", "e")
|
||||
.remplacer("ë", "e")
|
||||
.remplacer("î", "i")
|
||||
.remplacer("ï", "i")
|
||||
.remplacer("ô", "o")
|
||||
.remplacer("ù", "u")
|
||||
.remplacer("ü", "u");
|
||||
}
|
||||
|
||||
function htmlifier(mot, langue){
|
||||
var res = '<span class="mot-' + langue + '">' + mot[langue] + '</span>';
|
||||
if (langue == "francais") {
|
||||
@@ -70,13 +50,13 @@ function htmlifier(mot, langue){
|
||||
function construitListe(traductions) {
|
||||
var langue = $( "#mots" ).attr("data-langue");
|
||||
|
||||
metAJourLienChange(langue);
|
||||
mettreAJourLienInversion(langue);
|
||||
|
||||
traductions = traductions["vrais mots"].concat(traductions["faux mots"]);
|
||||
// tri par ordre alphabétique de la langue de départ
|
||||
traductions.tri(function(traduction1, traduction2){
|
||||
var s1 = sansAccents(traduction1[langue]);
|
||||
var s2 = sansAccents(traduction2[langue]);
|
||||
// trier par ordre alphabétique de la langue de départ
|
||||
traductions.trier(function(traduction1, traduction2){
|
||||
var s1 = traduction1[langue].enMinuscules().sansAccents();
|
||||
var s2 = traduction2[langue].enMinuscules().sansAccents();
|
||||
if (s1 > s2) {
|
||||
return 1;
|
||||
}
|
||||
@@ -92,7 +72,7 @@ function construitListe(traductions) {
|
||||
var l = '';
|
||||
for (var i=0; i < traductions.longueur(); i++) {
|
||||
var mot = traductions[i];
|
||||
var c = sansAccents(mot[langue]).caractereA(0).enMajuscules();
|
||||
var c = mot[langue].caractereA(0).enMajuscules().sansAccents();
|
||||
|
||||
|
||||
if (c != l) {
|
||||
@@ -129,7 +109,7 @@ function construitListe(traductions) {
|
||||
$(function() {
|
||||
$.recupererJSON( "traductions.json", function( traductions ) {
|
||||
construitListe(traductions);
|
||||
$( "#lienChange" ).clic( function() {changeDeSens(traductions);} );
|
||||
$( "#lienInversion" ).clic( function() {inverser(traductions);} );
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
59
js/prototypes-fr.js
vendored
Normal file
59
js/prototypes-fr.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
var Objet = Object
|
||||
Objet.creer = Objet.create
|
||||
|
||||
var Chaine = String
|
||||
Chaine.prototype.enMinuscules = Chaine.prototype.toLowerCase
|
||||
Chaine.prototype.enMajuscules = Chaine.prototype.toUpperCase
|
||||
Chaine.prototype.remplacer = Chaine.prototype.replace
|
||||
Chaine.prototype.caractereA = Chaine.prototype.charAt
|
||||
Chaine.prototype.sansAccents = function () {
|
||||
// Faute d'une bibliotheque unidecode, nous nous limitons aux lettres
|
||||
// accentuées du français.
|
||||
// https://fr.wikipedia.org/wiki/Diacritiques_utilisés_en_français
|
||||
return this
|
||||
.remplacer("à", "a")
|
||||
.remplacer("â", "a")
|
||||
.remplacer("ç", "c")
|
||||
.remplacer("é", "e")
|
||||
.remplacer("è", "e")
|
||||
.remplacer("ê", "e")
|
||||
.remplacer("ë", "e")
|
||||
.remplacer("î", "i")
|
||||
.remplacer("ï", "i")
|
||||
.remplacer("ô", "o")
|
||||
.remplacer("ù", "u")
|
||||
.remplacer("ü", "u")
|
||||
.remplacer("À", "A")
|
||||
.remplacer("Â", "A")
|
||||
.remplacer("Ç", "C")
|
||||
.remplacer("É", "E")
|
||||
.remplacer("È", "E")
|
||||
.remplacer("Ê", "E")
|
||||
.remplacer("Ë", "E")
|
||||
.remplacer("Î", "I")
|
||||
.remplacer("Ï", "I")
|
||||
.remplacer("Ô", "O")
|
||||
.remplacer("Ù", "U")
|
||||
.remplacer("Ü", "U");
|
||||
}
|
||||
|
||||
|
||||
var Tableau = Array
|
||||
Tableau.prototype.trier = Tableau.prototype.sort
|
||||
Tableau.prototype.longueur = function () { return this.length; }
|
||||
Tableau.prototype.pousser = Tableau.prototype.push
|
||||
|
||||
document.creerElement = document.createElement
|
||||
document.recupererElementParNomDEtiquette = document.getElementsByTagName;
|
||||
document.localisation = document.location;
|
||||
document.localisation.protocole = document.localisation.protocole;
|
||||
|
||||
jQuery.fn.extend({
|
||||
clic: function (x) { return this.click(x); },
|
||||
enfants: function () { return this.children(); },
|
||||
dernier: function () { return this.last(); },
|
||||
ajouter: function (x) { return this.append(x); }
|
||||
});
|
||||
$.recupererJSON = $.getJSON
|
||||
Reference in New Issue
Block a user