Skip to content

Commit e3b054b

Browse files
Glue our translations to the simulator. (#925)
It doesn't need much text so no need for it to have a translation mechanism of its own. Could revisit if there's third-party demand - if we had translations at that point we could just inline them. Co-authored-by: Robert Knight <[email protected]>
1 parent ae3c704 commit e3b054b

File tree

8 files changed

+119
-1
lines changed

8 files changed

+119
-1
lines changed

lang/ui.en.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,14 @@
779779
"defaultMessage": "Simulator actions",
780780
"description": "Aria label for the bar with simulator actions"
781781
},
782+
"simulator-button-a": {
783+
"defaultMessage": "Button A",
784+
"description": "Button A aria label on the simulator board"
785+
},
786+
"simulator-button-b": {
787+
"defaultMessage": "Button B",
788+
"description": "Button B aria label on the simulator board"
789+
},
782790
"simulator-button-hold-label": {
783791
"defaultMessage": "Hold button {button}",
784792
"description": "Aria label for simulator toggle button"
@@ -939,6 +947,10 @@
939947
"defaultMessage": "Sound level",
940948
"description": "Sound level title"
941949
},
950+
"simulator-start-simulator": {
951+
"defaultMessage": "Start simulator",
952+
"description": "Aria label for the large play button on the simulator board"
953+
},
942954
"simulator-stop": {
943955
"defaultMessage": "Stop",
944956
"description": "Aria label for the stop simulator button"

lang/ui.fr.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,14 @@
778778
"defaultMessage": "Simulator actions",
779779
"description": "Aria label for the bar with simulator actions"
780780
},
781+
"simulator-button-a": {
782+
"defaultMessage": "Button A",
783+
"description": "Button A aria label on the simulator board"
784+
},
785+
"simulator-button-b": {
786+
"defaultMessage": "Button B",
787+
"description": "Button B aria label on the simulator board"
788+
},
781789
"simulator-button-hold-label": {
782790
"defaultMessage": "Hold button {button}",
783791
"description": "Aria label for simulator toggle button"
@@ -938,6 +946,10 @@
938946
"defaultMessage": "Sound level",
939947
"description": "Sound level title"
940948
},
949+
"simulator-start-simulator": {
950+
"defaultMessage": "Start simulator",
951+
"description": "Aria label for the large play button on the simulator board"
952+
},
941953
"simulator-stop": {
942954
"defaultMessage": "Stop",
943955
"description": "Aria label for the stop simulator button"

lang/ui.lol.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,14 @@
778778
"defaultMessage": "Simulator actions",
779779
"description": "Aria label for the bar with simulator actions"
780780
},
781+
"simulator-button-a": {
782+
"defaultMessage": "Button A",
783+
"description": "Button A aria label on the simulator board"
784+
},
785+
"simulator-button-b": {
786+
"defaultMessage": "Button B",
787+
"description": "Button B aria label on the simulator board"
788+
},
781789
"simulator-button-hold-label": {
782790
"defaultMessage": "Hold button {button}",
783791
"description": "Aria label for simulator toggle button"
@@ -938,6 +946,10 @@
938946
"defaultMessage": "Sound level",
939947
"description": "Sound level title"
940948
},
949+
"simulator-start-simulator": {
950+
"defaultMessage": "Start simulator",
951+
"description": "Aria label for the large play button on the simulator board"
952+
},
941953
"simulator-stop": {
942954
"defaultMessage": "Stop",
943955
"description": "Aria label for the stop simulator button"

src/device/simulator.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export type SensorStateKey = Extract<
111111
| "buttonB"
112112
>;
113113

114+
interface Config {
115+
language: string;
116+
translations: Record<string, string>;
117+
}
118+
114119
export interface DataLog {
115120
headings: string[];
116121
data: DataLogRow[];
@@ -250,6 +255,10 @@ export class SimulatorDeviceConnection
250255
this.emit(EVENT_FLASH);
251256
}
252257

258+
configure(config: Config): void {
259+
this.postMessage("config", config);
260+
}
261+
253262
private notifyResetComms() {
254263
// Might be nice to rework so this was all about connection state changes.
255264
this.emit(EVENT_SERIAL_RESET, {});

src/messages/ui.en.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,18 @@
17651765
"value": "Simulator actions"
17661766
}
17671767
],
1768+
"simulator-button-a": [
1769+
{
1770+
"type": 0,
1771+
"value": "Button A"
1772+
}
1773+
],
1774+
"simulator-button-b": [
1775+
{
1776+
"type": 0,
1777+
"value": "Button B"
1778+
}
1779+
],
17681780
"simulator-button-hold-label": [
17691781
{
17701782
"type": 0,
@@ -2075,6 +2087,12 @@
20752087
"value": "Sound level"
20762088
}
20772089
],
2090+
"simulator-start-simulator": [
2091+
{
2092+
"type": 0,
2093+
"value": "Start simulator"
2094+
}
2095+
],
20782096
"simulator-stop": [
20792097
{
20802098
"type": 0,

src/messages/ui.fr.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,18 @@
17651765
"value": "Simulator actions"
17661766
}
17671767
],
1768+
"simulator-button-a": [
1769+
{
1770+
"type": 0,
1771+
"value": "Button A"
1772+
}
1773+
],
1774+
"simulator-button-b": [
1775+
{
1776+
"type": 0,
1777+
"value": "Button B"
1778+
}
1779+
],
17681780
"simulator-button-hold-label": [
17691781
{
17701782
"type": 0,
@@ -2075,6 +2087,12 @@
20752087
"value": "Sound level"
20762088
}
20772089
],
2090+
"simulator-start-simulator": [
2091+
{
2092+
"type": 0,
2093+
"value": "Start simulator"
2094+
}
2095+
],
20782096
"simulator-stop": [
20792097
{
20802098
"type": 0,

src/messages/ui.lol.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,18 @@
17091709
"value": "Simulator actions"
17101710
}
17111711
],
1712+
"simulator-button-a": [
1713+
{
1714+
"type": 0,
1715+
"value": "Button A"
1716+
}
1717+
],
1718+
"simulator-button-b": [
1719+
{
1720+
"type": 0,
1721+
"value": "Button B"
1722+
}
1723+
],
17121724
"simulator-button-hold-label": [
17131725
{
17141726
"type": 0,
@@ -2019,6 +2031,12 @@
20192031
"value": "Sound level"
20202032
}
20212033
],
2034+
"simulator-start-simulator": [
2035+
{
2036+
"type": 0,
2037+
"value": "Start simulator"
2038+
}
2039+
],
20222040
"simulator-stop": [
20232041
{
20242042
"type": 0,

src/simulator/Simulator.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { AspectRatio, Box, Flex, useToken, VStack } from "@chakra-ui/react";
77
import { useEffect, useRef, useState } from "react";
8-
import { useIntl } from "react-intl";
8+
import { IntlShape, useIntl } from "react-intl";
99
import HideSplitViewButton from "../common/SplitView/HideSplitViewButton";
1010
import { useResizeObserverContentRect } from "../common/use-resize-observer";
1111
import { topBarHeight } from "../deployment/misc";
@@ -53,6 +53,9 @@ const Simulator = ({
5353
sim.dispose();
5454
};
5555
}, []);
56+
useEffect(() => {
57+
updateTranslations(simulator.current, intl);
58+
}, [simulator, intl]);
5659
const simControlsRef = useRef<HTMLDivElement>(null);
5760
const contentRect = useResizeObserverContentRect(simControlsRef);
5861
const simHeight = contentRect?.height ?? 0;
@@ -118,4 +121,20 @@ const Simulator = ({
118121
);
119122
};
120123

124+
const updateTranslations = (
125+
simulator: SimulatorDeviceConnection,
126+
intl: IntlShape
127+
) => {
128+
const config = {
129+
language: intl.locale,
130+
translations: Object.fromEntries(
131+
["button-a", "button-b", "touch-logo", "start-simulator"].map((k) => [
132+
k,
133+
intl.formatMessage({ id: "simulator-" + k }),
134+
])
135+
),
136+
};
137+
simulator.configure(config);
138+
};
139+
121140
export default Simulator;

0 commit comments

Comments
 (0)