Skip to content

Commit f83a370

Browse files
committed
Update dataviz to use translations
1 parent 8aee4b7 commit f83a370

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

src/commons/sideContent/content/SideContentCseMachine.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,12 @@ const makeCseMachineTabFrom = (location: NonStoryWorkspaceLocation): SideContent
548548
id: SideContentType.cseMachine
549549
});
550550

551-
const ItalicLink: React.FC<{ href: string; children?: React.ReactNode }> = ({ href, children }) => {
551+
export const ItalicLink: React.FC<{ href: string; children?: React.ReactNode }> = ({
552+
href,
553+
children
554+
}) => {
552555
return (
553-
<a href={Links.textbookChapter3_2} rel="noopener noreferrer" target="_blank">
556+
<a href={href} rel="noopener noreferrer" target="_blank">
554557
<i>{children}</i>
555558
</a>
556559
);

src/commons/sideContent/content/SideContentDataVisualizer.tsx

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { HotkeyItem } from '@mantine/hooks';
44
import { bindActionCreators } from '@reduxjs/toolkit';
55
import classNames from 'classnames';
66
import React from 'react';
7+
import { Trans, useTranslation } from 'react-i18next';
78
import { connect, MapDispatchToProps } from 'react-redux';
89
import HotKeys from 'src/commons/hotkeys/HotKeys';
910

@@ -12,6 +13,7 @@ import { Step } from '../../../features/dataVisualizer/dataVisualizerTypes';
1213
import { Links } from '../../utils/Constants';
1314
import { beginAlertSideContent } from '../SideContentActions';
1415
import { SideContentLocation, SideContentTab, SideContentType } from '../SideContentTypes';
16+
import { ItalicLink } from './SideContentCseMachine';
1517

1618
type State = {
1719
steps: Step[];
@@ -127,36 +129,7 @@ class SideContentDataVisualizerBase extends React.Component<OwnProps & DispatchP
127129
))}
128130
</div>
129131
) : (
130-
<p id="data-visualizer-default-text" className={Classes.RUNNING_TEXT}>
131-
The data visualizer helps you to visualize data structures.
132-
{this.state.steps}
133-
<br />
134-
<br />
135-
It is activated by calling the function{' '}
136-
<code>
137-
draw_data(x<sub>1</sub>, x<sub>2</sub>, ... x<sub>n</sub>)
138-
</code>
139-
, where{' '}
140-
<code>
141-
x<sub>k</sub>
142-
</code>{' '}
143-
would be the{' '}
144-
<code>
145-
k<sup>th</sup>
146-
</code>{' '}
147-
data structure that you want to visualize and <code>n</code> is the number of
148-
structures.
149-
<br />
150-
<br />
151-
The data visualizer uses box-and-pointer diagrams, as introduced in{' '}
152-
<a href={Links.textbookChapter2_2} rel="noopener noreferrer" target="_blank">
153-
<i>
154-
Structure and Interpretation of Computer Programs, JavaScript Edition, Chapter 2,
155-
Section 2
156-
</i>
157-
</a>
158-
.
159-
</p>
132+
<DataVisualizerDefaultText />
160133
)}
161134
</div>
162135
</HotKeys>
@@ -199,4 +172,38 @@ const makeDataVisualizerTabFrom = (location: SideContentLocation): SideContentTa
199172
id: SideContentType.dataVisualizer
200173
});
201174

175+
const DataVisualizerDefaultText: React.FC = () => {
176+
const { t } = useTranslation('sideContent', { keyPrefix: 'dataVisualizer' });
177+
return (
178+
<p id="data-visualizer-default-text" className={Classes.RUNNING_TEXT}>
179+
{t('defaultText')}
180+
<br />
181+
<br />
182+
<Trans
183+
ns="sideContent"
184+
i18nKey="dataVisualizer.instructions"
185+
components={[
186+
<code>
187+
draw_data(x<sub>1</sub>, x<sub>2</sub>, ... x<sub>n</sub>)
188+
</code>,
189+
<code>
190+
x<sub>k</sub>
191+
</code>,
192+
<code>
193+
k<sup>th</sup>
194+
</code>,
195+
<code>n</code>
196+
]}
197+
/>
198+
<br />
199+
<br />
200+
<Trans
201+
ns="sideContent"
202+
i18nKey="dataVisualizer.reference"
203+
components={[<ItalicLink href={Links.textbookChapter2_2} />]}
204+
/>
205+
</p>
206+
);
207+
};
208+
202209
export default makeDataVisualizerTabFrom;

src/i18n/locales/en/sideContent/dataVisualizer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"defaultText": "The data visualizer helps you to visualize data structures.",
3-
"instructions": "It is activated by calling the function draw_data(x₁, x₂, ... xₙ), where xₖ would be the kᵗʰ data structure that you want to visualize and n is the number of structures.",
4-
"reference": "The data visualizer uses box-and-pointer diagrams, as introduced in Structure and Interpretation of Computer Programs, JavaScript Edition, Chapter 2, Section 2.",
3+
"instructions": "It is activated by calling the function <0/>, where <1/> would be the <2/> data structure that you want to visualize and <3/> is the number of structures.",
4+
"reference": "The data visualizer uses box-and-pointer diagrams, as introduced in <0>Structure and Interpretation of Computer Programs, JavaScript Edition, Chapter 2, Section 2</0>.",
55
"label": "Data Visualizer",
66
"previous": "Previous",
77
"next": "Next"

src/i18n/locales/zh-SG/sideContent/dataVisualizer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"defaultText": "数据可视化工具帮助您可视化数据结构。",
3-
"instructions": "通过调用函数 draw_data(x₁, x₂, ... xₙ) 激活,其中 xÔéû 是您想要可视化的 kßÁù╩░ 数据结构,n 是结构的数量。",
4-
"reference": "数据可视化工具使用框图和指针图,这些图基于《计算机程序的构造和解释,JavaScript 版》第 2 章第 2 节中介绍的符号",
3+
"instructions": "通过调用函数 <0/> 激活,其中 <1/> 是您想要可视化的 <2/> 数据结构,<3/> 是结构的数量。",
4+
"reference": "数据可视化工具使用框图和指针图,这些图基于<0>《计算机程序的构造和解释,JavaScript 版》第 2 章第 2 节</0>中介绍的符号",
55
"label": "数据可视化工具",
66
"previous": "上一个",
77
"next": "下一个"

0 commit comments

Comments
 (0)