Add english localization for local image generation

parent c5ec38e2
Pipeline #1460 passed with stage
in 37 seconds
......@@ -4,6 +4,15 @@ let sampleSignatures = ["\t", "moi\t", "les gens sympas\t", "les gens biens\t"];
let canvas = document.getElementById('output');
let ctx = canvas.getContext('2d');
let enLocale = {
"Internet,": "Internet,",
"et libertés.": "and freedom.",
"Faites comme ": "Just like ",
"outenez ": "upport ",
"moi\t": "me\t",
"les gens sympas\t": "nice people\t",
"les gens biens\t": "cool people\t"
};
let width = canvas.width;
let height = canvas.height;
......@@ -30,6 +39,14 @@ let getImage = function(id, cb) {
}
}
let language = function() {
return navigator.language.indexOf('en') !== -1 ? 'en' : 'fr';
}
let _ = function(str) {
return language() === 'en' ? enLocale[str] || str : str;
}
let draw = function() {
let bgColor = document.querySelector('.colorpicker input[type="radio"][name="bg-color"]:checked').value;
let fgColor = document.querySelector('.colorpicker input[type="radio"][name="fg-color"]:checked').value;
......@@ -54,8 +71,8 @@ let draw = function() {
ctx.fillStyle = '#497ed5';
let offset = height * 0.05;
if (signature) {
ctx.fillText('Faites comme ', offset, height * 0.9);
offset += ctx.measureText('Faites comme ').width;
ctx.fillText(_('Faites comme '), offset, height * 0.9);
offset += ctx.measureText(_('Faites comme ')).width;
ctx.font = 'bold 12pt FiraSans';
ctx.fillText(signature, offset, height * 0.9);
offset += ctx.measureText(signature).width;
......@@ -66,8 +83,8 @@ let draw = function() {
ctx.fillText('S', offset, height * 0.9);
offset+= ctx.measureText('S').width;
}
ctx.fillText('outenez ', offset, height * 0.9);
offset += ctx.measureText('outenez ').width;
ctx.fillText(_('outenez '), offset, height * 0.9);
offset += ctx.measureText(_('outenez ')).width;
ctx.font = 'bold 12pt FiraSans';
ctx.fillText('La Quadrature du Net !', offset, height * 0.9);
......@@ -83,8 +100,8 @@ let draw = function() {
ctx.font = fontSize + 'pt FiraSans';
ctx.fillStyle = 'white';
ctx.textBaseline = 'top';
ctx.fillText('Internet,', width * 0.08, height * 0.2);
ctx.fillText('et libertés.', width * 0.08, height * 0.2 + fontSize * 2.8);
ctx.fillText(_('Internet,'), width * 0.08, height * 0.2);
ctx.fillText(_('et libertés.'), width * 0.08, height * 0.2 + fontSize * 2.8);
ctx.font = fontSize + 'pt ' + font;
ctx.fillStyle = fgColor;
ctx.fillText(fillText, width * 0.08, height * 0.2 + fontSize * 1.4);
......@@ -181,9 +198,9 @@ for (let i = 0; i < randomButtons.length; ++i) {
== document.querySelector('.colorpicker input[type="radio"][name="fg-color"]:checked').value);
randomElement('input[name="font"]').checked = true;
randomElement('input[name="icon"]').checked = true;
document.getElementById('step2value').value = document.getElementById('step2value').innerText = sampleTexts[Math.trunc(Math.random() * sampleTexts.length)];
document.getElementById('step2value').value = document.getElementById('step2value').innerText = _(sampleTexts[Math.trunc(Math.random() * sampleTexts.length)]);
if (document.getElementById('signature').value.match(/(\t$|^$)/))
document.getElementById('signature').value = sampleSignatures[Math.trunc(Math.random() * sampleSignatures.length)];
document.getElementById('signature').value = _(sampleSignatures[Math.trunc(Math.random() * sampleSignatures.length)]);
draw();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment