Add Spanish translations #7

Closed
jcalvento wants to merge 4 commits from add-spanish-translations into master
6 changed files with 40 additions and 51 deletions
Showing only changes of commit 7582b76ee1 - Show all commits

View File

@ -16,5 +16,10 @@ if (!game) {
require('babel-polyfill');
const gameToPlay = require(__dirname + '/build/' + game).default;
gameToPlay(language);
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
const Polyglot = require('node-polyglot');
const i18n = new Polyglot({phrases: locale});
gameToPlay(i18n);

View File

@ -1,6 +1,5 @@
import Unit from './classes/unit';
import Interface from './classes/interface';
import Polyglot from "node-polyglot";
let FRAME = 100;
let ui = new Interface();
@ -24,7 +23,7 @@ point.random();
let score = 0;
let stop = false;
function loop(polyglot) {
function loop(i18n) {
if (stop) return;
ui.clear();
@ -69,23 +68,6 @@ ui.onKey('left', () => {
changeDirection(LEFT);
});
ui.onKey(() => {
if (!stop) return;
stop = false;
snake = [];
head = createPart();
head.color = '#71da29';
createPart();
createPart();
score = 0;
point.random();
loop();
})
function changeDirection(dir) {
if (head.direction === UP && dir === DOWN ||
head.direction === DOWN && dir === UP ||
@ -120,17 +102,17 @@ function createPart() {
if (this.direction !== ahead.direction) {
this.changeTo = ahead.direction;
}
}
};
part.speed = function(multiplier = 1) {
let { direction } = part;
let x = direction == LEFT ? -1 :
direction == RIGHT ? 1 : 0;
let y = direction == UP ? -1 :
direction == DOWN ? 1 : 0;
let x = direction === LEFT ? -1 :
direction === RIGHT ? 1 : 0;
let y = direction === UP ? -1 :
direction === DOWN ? 1 : 0;
return [x * multiplier, y * multiplier];
}
};
let [dX, dY] = part.speed();
dX *= -1;
@ -168,10 +150,23 @@ process.on('exit', function() {
ui.cursor.show();
});
export default function(language) {
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
const i18n = new Polyglot({phrases: locale});
export default function(i18n) {
loop(i18n);
ui.onKey(() => {
if (!stop) return;
stop = false;
snake = [];
head = createPart();
head.color = '#71da29';
createPart();
createPart();
score = 0;
point.random();
loop(i18n);
});
}

View File

@ -1,6 +1,5 @@
import Unit from './classes/unit';
import Interface from './classes/interface';
import Polyglot from "node-polyglot";
const FRAME = 20;
let ENEMY_SPAWN_RATE = 1000;
@ -22,11 +21,7 @@ let missles = [];
let enemies = [];
let score = 0;
export default function(language) {
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
const i18n = new Polyglot({phrases: locale});
export default function(i18n) {
setInterval((i18n) => {
ui.clear();
@ -62,9 +57,9 @@ export default function(language) {
enemies.splice(i, 1);
}
if (enemy.killed == 3) enemy.dead = true;
if (enemy.killed === 3) enemy.dead = true;
if (enemy.killed < 3) enemy.killed++;
})
});
ui.cursor.goto(0, 0).yellow().write(`${i18n.t('spacecraft.score')}: ${score}`);
ui.cursor.reset();
@ -110,7 +105,7 @@ ui.onKey('space', () => {
enemy.speed = () => {
return [Math.random() > 0.9 ? 0.4 : 0, 0.06];
}
};
enemies.push(enemy);
@ -118,6 +113,6 @@ ui.onKey('space', () => {
}());
process.on('exit', function() {
ui.cursor.horizontalAbsolute(0).eraseLine()
ui.cursor.horizontalAbsolute(0).eraseLine();
ui.cursor.show();
});

View File

@ -1,7 +1,5 @@
import Unit from './classes/unit';
import Tank from './classes/tank';
import Interface from './classes/interface';
import Polyglot from "node-polyglot";
let FRAME = 50;
let ui = new Interface();
@ -90,13 +88,13 @@ ui.onKey('down', () => {
if (immoblize) return;
turn().angle -= 1;
})
});
ui.onKey('up', () => {
if (immoblize) return;
turn().angle += 1;
})
});
ui.onKey('left', () => {
if (immoblize) return;
@ -134,7 +132,7 @@ ui.onKey(() => {
loop();
}
})
});
let TURN = true;
function turn() {
@ -142,10 +140,6 @@ function turn() {
return two;
}
export default function(language) {
const locale = require(`${__dirname}/locales/${language || 'en'}.json`);
const i18n = new Polyglot({phrases: locale});
export default function(i18n) {
loop(i18n);
}