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 1 commit
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
16 changes: 16 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 A aria label on the simulator board"
},
"simulator-button-hold-label": {
"defaultMessage": "Hold button {button}",
"description": "Aria label for simulator toggle button"
Expand All @@ -787,6 +795,10 @@
"defaultMessage": "Press button {button}",
"description": "Aria label for simulator push button"
},
"simulator-button-touch-logo": {
"defaultMessage": "Touch logo",
"description": "Touch logo aria label on the simulator board"
},
"simulator-buttons": {
"defaultMessage": "Buttons",
"description": "Buttons title"
Expand Down Expand Up @@ -931,6 +943,10 @@
"defaultMessage": "Sound level",
"description": "Sound level title"
},
"simulator-start-simulator": {
"defaultMessage": "Button A",
"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
16 changes: 16 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 A aria label on the simulator board"
},
"simulator-button-hold-label": {
"defaultMessage": "Hold button {button}",
"description": "Aria label for simulator toggle button"
Expand All @@ -786,6 +794,10 @@
"defaultMessage": "Press button {button}",
"description": "Aria label for simulator push button"
},
"simulator-button-touch-logo": {
"defaultMessage": "Touch logo",
"description": "Touch logo aria label on the simulator board"
},
"simulator-buttons": {
"defaultMessage": "Buttons",
"description": "Buttons title"
Expand Down Expand Up @@ -930,6 +942,10 @@
"defaultMessage": "Sound level",
"description": "Sound level title"
},
"simulator-start-simulator": {
"defaultMessage": "Button A",
"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
16 changes: 16 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 A aria label on the simulator board"
},
"simulator-button-hold-label": {
"defaultMessage": "Hold button {button}",
"description": "Aria label for simulator toggle button"
Expand All @@ -786,6 +794,10 @@
"defaultMessage": "Press button {button}",
"description": "Aria label for simulator push button"
},
"simulator-button-touch-logo": {
"defaultMessage": "Touch logo",
"description": "Touch logo aria label on the simulator board"
},
"simulator-buttons": {
"defaultMessage": "Buttons",
"description": "Buttons title"
Expand Down Expand Up @@ -930,6 +942,10 @@
"defaultMessage": "Sound level",
"description": "Sound level title"
},
"simulator-start-simulator": {
"defaultMessage": "Button A",
"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
24 changes: 24 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 All @@ -1785,6 +1797,12 @@
"value": "button"
}
],
"simulator-button-touch-logo": [
{
"type": 0,
"value": "Touch logo"
}
],
"simulator-buttons": [
{
"type": 0,
Expand Down Expand Up @@ -2063,6 +2081,12 @@
"value": "Sound level"
}
],
"simulator-start-simulator": [
{
"type": 0,
"value": "Button A"
}
],
"simulator-stop": [
{
"type": 0,
Expand Down
24 changes: 24 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 All @@ -1785,6 +1797,12 @@
"value": "button"
}
],
"simulator-button-touch-logo": [
{
"type": 0,
"value": "Touch logo"
}
],
"simulator-buttons": [
{
"type": 0,
Expand Down Expand Up @@ -2063,6 +2081,12 @@
"value": "Sound level"
}
],
"simulator-start-simulator": [
{
"type": 0,
"value": "Button A"
}
],
"simulator-stop": [
{
"type": 0,
Expand Down
24 changes: 24 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 All @@ -1729,6 +1741,12 @@
"value": "button"
}
],
"simulator-button-touch-logo": [
{
"type": 0,
"value": "Touch logo"
}
],
"simulator-buttons": [
{
"type": 0,
Expand Down Expand Up @@ -2007,6 +2025,12 @@
"value": "Sound level"
}
],
"simulator-start-simulator": [
{
"type": 0,
"value": "Button A"
}
],
"simulator-stop": [
{
"type": 0,
Expand Down
28 changes: 24 additions & 4 deletions 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 @@ -33,10 +33,10 @@ const Simulator = ({
minWidth,
}: SimulatorProps) => {
// This needs the domain to be updated before we release.
const url = "https://stage-python-simulator.microbit.org/simulator.html";
//const url = "https://stage-python-simulator.microbit.org/simulator.html";
// For testing with sim branches:
//const branch = "whatever";
//const url = `https://review-python-simulator.microbit.org/${branch}/simulator.html`;
const branch = "i18n-1";
const url = `https://review-python-simulator.microbit.org/${branch}/simulator.html`;

const ref = useRef<HTMLIFrameElement>(null);
const intl = useIntl();
Expand All @@ -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,21 @@ 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 }),
])
),
};
console.log("Reconfiguring sim", config);
simulator.configure(config);
};

export default Simulator;