Skip to content

Commit

Permalink
more i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
allanjoseph98 committed Jan 4, 2025
1 parent 4c076f9 commit cf05aa8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
29 changes: 14 additions & 15 deletions ui/puzzle/src/plugins/puzzle.nvui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function initModule() {
ctrl.streak ? '.puzzle--streak' : ''
}`,
h('div.nvui', [
h('h1', `Puzzle: ${ctrl.pov} to play.`),
h('h2', 'Puzzle info'),
puzzleBox(ctrl),
theme(ctrl),
Expand All @@ -82,8 +81,8 @@ export function initModule() {
{ attrs: { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' } },
renderStatus(ctrl),
),
h('div.replay', renderReplay(ctrl)),
...(ctrl.streak ? renderStreak(ctrl) : []),
ctrl.data.replay && h('div.replay', renderReplay(ctrl)),
ctrl.streak && renderStreak(ctrl),
h('h2', 'Last move'),
h(
'p.lastMove',
Expand All @@ -103,7 +102,9 @@ export function initModule() {
},
[
h('label', [
ctrl.mode === 'view' ? 'Command input' : `Find the best move for ${ctrl.pov}.`,
ctrl.mode === 'view'
? 'Command input'
: `${i18n.puzzle[ctrl.pov === 'white' ? 'findTheBestMoveForWhite' : 'findTheBestMoveForBlack']}`,
h('input.move.mousetrap', {
attrs: { name: 'move', type: 'text', autocomplete: 'off', autofocus: true },
}),
Expand Down Expand Up @@ -169,7 +170,7 @@ export function initModule() {
...(!ctrl.data.replay && !ctrl.streak
? [h('h3', 'Puzzle Settings'), renderDifficultyForm(ctrl)]
: []),
h('h2', 'Keyboard shortcuts'),
h('h2', i18n.site.keyboardShortcuts),
h('p', [
`Left and right arrow keys: ${i18n.site.keyMoveBackwardOrForward}`,
h('br'),
Expand Down Expand Up @@ -239,7 +240,7 @@ const isYourMove = (ctrl: PuzzleCtrl): boolean =>
ctrl.node.children.length === 0 || ctrl.node.children[0].puzzle === 'fail';

const browseHint = (ctrl: PuzzleCtrl): string[] =>
ctrl.mode !== 'view' && !isYourMove(ctrl) ? ['You browsed away from the latest position.'] : [];
ctrl.mode !== 'view' && !isYourMove(ctrl) ? [i18n.site.youBrowsedAway] : [];

const shortCommands = ['l', 'last', 'p', 's', 'v'];

Expand All @@ -266,7 +267,7 @@ function viewOrAdvanceSolution(ctrl: PuzzleCtrl, notify: (txt: string) => void):
if (isInSolution(next) || (isInSolution(node) && isInSolution(nextNext))) {
controlNext(ctrl);
ctrl.redraw();
} else if (isInSolution(node)) notify('Puzzle complete!');
} else if (isInSolution(node)) notify(i18n.puzzle.puzzleComplete);
else ctrl.viewSolution();
} else ctrl.viewSolution();
}
Expand All @@ -284,7 +285,7 @@ const renderStreak = (ctrl: PuzzleCtrl): VNode[] =>

function renderStatus(ctrl: PuzzleCtrl): string {
if (ctrl.mode !== 'view') return 'Solving';
else if (ctrl.streak) return `GAME OVER. Your streak: ${ctrl.streak.data.index}`;
else if (ctrl.streak) return `GAME OVER. ${i18n.puzzle.yourStreakX(ctrl.streak.data.index)}`;
else if (ctrl.lastFeedback === 'win') return i18n.puzzle.puzzleSuccess;
else return i18n.puzzle.puzzleComplete;
}
Expand All @@ -300,14 +301,14 @@ function renderReplay(ctrl: PuzzleCtrl): string {
const playActions = (ctrl: PuzzleCtrl): VNode =>
ctrl.streak
? button(i18n.storm.skip, ctrl.skip, i18n.puzzle.streakSkipExplanation, !ctrl.streak.data.skip)
: h('div.actions_play', button('View the solution', ctrl.viewSolution));
: h('div.actions_play', button(i18n.site.viewTheSolution, ctrl.viewSolution));

const afterActions = (ctrl: PuzzleCtrl): VNode =>
h(
'div.actions_after',
ctrl.streak && ctrl.lastFeedback === 'win'
? anchor(i18n.puzzle.newStreak, '/streak')
: [...renderVote(ctrl), button('Continue training', ctrl.nextPuzzle)],
? h('a', { attrs: { href: '/streak' } }, i18n.puzzle.newStreak)
: [...renderVote(ctrl), button(i18n.puzzle.continueTraining, ctrl.nextPuzzle)],
);

const renderVoteTutorial = (ctrl: PuzzleCtrl): VNode[] =>
Expand All @@ -320,12 +321,10 @@ const renderVote = (ctrl: PuzzleCtrl): VNode[] =>
? []
: [
...renderVoteTutorial(ctrl),
button('Thumbs up', () => ctrl.vote(true), undefined, ctrl.voteDisabled),
button('Thumbs down', () => ctrl.vote(false), undefined, ctrl.voteDisabled),
button(i18n.puzzle.upVote, () => ctrl.vote(true), undefined, ctrl.voteDisabled),
button(i18n.puzzle.downVote, () => ctrl.vote(false), undefined, ctrl.voteDisabled),
];

const anchor = (text: string, href: string): VNode => h('a', { attrs: { href } }, text);

const button = (text: string, action: (e: Event) => void, title?: string, disabled?: boolean): VNode =>
h(
'button',
Expand Down
13 changes: 7 additions & 6 deletions ui/round/src/plugins/round.nvui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function initModule(): NvuiPlugin {
...['white', 'black'].map((color: Color) =>
h('p', [color + ' player: ', playerHtml(ctrl, ctrl.playerByColor(color))]),
),
h('p', `${d.game.rated ? 'Rated' : 'Casual'} ${d.game.perf}`),
h('p', `${d.game.rated ? i18n.site.rated : i18n.site.casual} ${d.game.perf}`),
d.clock ? h('p', `Clock: ${d.clock.initial / 60} + ${d.clock.increment}`) : null,
h('h2', 'Moves'),
h('p.moves', { attrs: { role: 'log', 'aria-live': 'off' } }, renderMoves(d.steps.slice(1), style)),
Expand Down Expand Up @@ -365,13 +365,14 @@ function gameText(ctrl: RoundController) {
return [
d.game.status.name === 'started'
? ctrl.isPlaying()
? 'You play the ' + ctrl.data.player.color + ' pieces.'
? ctrl.data.player.color === 'white'
? i18n.site.youPlayTheWhitePieces
: i18n.site.youPlayTheBlackPieces
: 'Spectating.'
: 'Game over.',
d.game.rated ? 'Rated' : 'Casual',
: i18n.site.gameOver,
d.game.rated ? i18n.site.rated : i18n.site.casual,
d.clock ? `${d.clock.initial / 60} + ${d.clock.increment}` : '',
d.game.perf,
'game versus',
playerText(ctrl, ctrl.data.opponent),
i18n.site.gameVsX(playerText(ctrl, ctrl.data.opponent)),
].join(' ');
}

0 comments on commit cf05aa8

Please sign in to comment.