Skip to content

Glue our translations to the simulator. #925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lang/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,14 @@
"defaultMessage": "Simulator actions",
"description": "Aria label for the bar with simulator actions"
},
"simulator-button-a": {
"defaultMessage": "Button A",
"description": "Button A aria label on the simulator board"
},
"simulator-button-b": {
"defaultMessage": "Button B",
"description": "Button B aria label on the simulator board"
},
"simulator-button-hold-label": {
"defaultMessage": "Hold button {button}",
"description": "Aria label for simulator toggle button"
Expand Down Expand Up @@ -931,6 +939,10 @@
"defaultMessage": "Sound level",
"description": "Sound level title"
},
"simulator-start-simulator": {
"defaultMessage": "Start simulator",
"description": "Aria label for the large play button on the simulator board"
},
"simulator-stop": {
"defaultMessage": "Stop",
"description": "Aria label for the stop simulator button"
Expand Down
12 changes: 12 additions & 0 deletions lang/ui.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,14 @@
"defaultMessage": "Simulator actions",
"description": "Aria label for the bar with simulator actions"
},
"simulator-button-a": {
"defaultMessage": "Button A",
"description": "Button A aria label on the simulator board"
},
"simulator-button-b": {
"defaultMessage": "Button B",
"description": "Button B aria label on the simulator board"
},
"simulator-button-hold-label": {
"defaultMessage": "Hold button {button}",
"description": "Aria label for simulator toggle button"
Expand Down Expand Up @@ -930,6 +938,10 @@
"defaultMessage": "Sound level",
"description": "Sound level title"
},
"simulator-start-simulator": {
"defaultMessage": "Start simulator",
"description": "Aria label for the large play button on the simulator board"
},
"simulator-stop": {
"defaultMessage": "Stop",
"description": "Aria label for the stop simulator button"
Expand Down
12 changes: 12 additions & 0 deletions lang/ui.lol.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,14 @@
"defaultMessage": "Simulator actions",
"description": "Aria label for the bar with simulator actions"
},
"simulator-button-a": {
"defaultMessage": "Button A",
"description": "Button A aria label on the simulator board"
},
"simulator-button-b": {
"defaultMessage": "Button B",
"description": "Button B aria label on the simulator board"
},
"simulator-button-hold-label": {
"defaultMessage": "Hold button {button}",
"description": "Aria label for simulator toggle button"
Expand Down Expand Up @@ -930,6 +938,10 @@
"defaultMessage": "Sound level",
"description": "Sound level title"
},
"simulator-start-simulator": {
"defaultMessage": "Start simulator",
"description": "Aria label for the large play button on the simulator board"
},
"simulator-stop": {
"defaultMessage": "Stop",
"description": "Aria label for the stop simulator button"
Expand Down
9 changes: 9 additions & 0 deletions src/device/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export type SensorStateKey = Extract<
| "buttonB"
>;

interface Config {
language: string;
translations: Record<string, string>;
}

export interface DataLog {
headings: string[];
data: DataLogRow[];
Expand Down Expand Up @@ -250,6 +255,10 @@ export class SimulatorDeviceConnection
this.emit(EVENT_FLASH);
}

configure(config: Config): void {
this.postMessage("config", config);
}

private notifyResetComms() {
// Might be nice to rework so this was all about connection state changes.
this.emit(EVENT_SERIAL_RESET, {});
Expand Down
18 changes: 18 additions & 0 deletions src/messages/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,18 @@
"value": "Simulator actions"
}
],
"simulator-button-a": [
{
"type": 0,
"value": "Button A"
}
],
"simulator-button-b": [
{
"type": 0,
"value": "Button B"
}
],
"simulator-button-hold-label": [
{
"type": 0,
Expand Down Expand Up @@ -2063,6 +2075,12 @@
"value": "Sound level"
}
],
"simulator-start-simulator": [
{
"type": 0,
"value": "Start simulator"
}
],
"simulator-stop": [
{
"type": 0,
Expand Down
18 changes: 18 additions & 0 deletions src/messages/ui.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,18 @@
"value": "Simulator actions"
}
],
"simulator-button-a": [
{
"type": 0,
"value": "Button A"
}
],
"simulator-button-b": [
{
"type": 0,
"value": "Button B"
}
],
"simulator-button-hold-label": [
{
"type": 0,
Expand Down Expand Up @@ -2063,6 +2075,12 @@
"value": "Sound level"
}
],
"simulator-start-simulator": [
{
"type": 0,
"value": "Start simulator"
}
],
"simulator-stop": [
{
"type": 0,
Expand Down
18 changes: 18 additions & 0 deletions src/messages/ui.lol.json
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,18 @@
"value": "Simulator actions"
}
],
"simulator-button-a": [
{
"type": 0,
"value": "Button A"
}
],
"simulator-button-b": [
{
"type": 0,
"value": "Button B"
}
],
"simulator-button-hold-label": [
{
"type": 0,
Expand Down Expand Up @@ -2007,6 +2019,12 @@
"value": "Sound level"
}
],
"simulator-start-simulator": [
{
"type": 0,
"value": "Start simulator"
}
],
"simulator-stop": [
{
"type": 0,
Expand Down
21 changes: 20 additions & 1 deletion src/simulator/Simulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { AspectRatio, Box, Flex, useToken, VStack } from "@chakra-ui/react";
import { useEffect, useRef, useState } from "react";
import { useIntl } from "react-intl";
import { IntlShape, useIntl } from "react-intl";
import HideSplitViewButton from "../common/SplitView/HideSplitViewButton";
import { useResizeObserverContentRect } from "../common/use-resize-observer";
import { topBarHeight } from "../deployment/misc";
Expand Down Expand Up @@ -53,6 +53,9 @@ const Simulator = ({
sim.dispose();
};
}, []);
useEffect(() => {
updateTranslations(simulator.current, intl);
}, [simulator, intl]);
const simControlsRef = useRef<HTMLDivElement>(null);
const contentRect = useResizeObserverContentRect(simControlsRef);
const simHeight = contentRect?.height ?? 0;
Expand Down Expand Up @@ -118,4 +121,20 @@ const Simulator = ({
);
};

const updateTranslations = (
simulator: SimulatorDeviceConnection,
intl: IntlShape
) => {
const config = {
language: intl.locale,
translations: Object.fromEntries(
["button-a", "button-b", "touch-logo", "start-simulator"].map((k) => [
k,
intl.formatMessage({ id: "simulator-" + k }),
])
),
};
simulator.configure(config);
};

export default Simulator;