Skip to content

Commit 4f39fb9

Browse files
committed
frontend/i18n: more support for i18n, e.g. in menu entries and editors
1 parent 682c673 commit 4f39fb9

File tree

19 files changed

+485
-118
lines changed

19 files changed

+485
-118
lines changed

src/packages/frontend/frame-editors/frame-tree/commands/format-commands.tsx

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { range } from "lodash";
2+
import { defineMessage } from "react-intl";
23

34
import AIAvatar from "@cocalc/frontend/components/ai-avatar";
45
import ColorPicker from "@cocalc/frontend/components/color-picker";
@@ -12,21 +13,48 @@ import { addEditorMenus } from "./editor-menus";
1213

1314
const FORMAT_SPEC = {
1415
equation: {
15-
button: "Math",
16-
label: "Inline Equation",
17-
title: "Insert inline LaTeX math equation.",
16+
button: defineMessage({
17+
id: "command.format.equation.button",
18+
defaultMessage: "Math",
19+
}),
20+
label: defineMessage({
21+
id: "command.format.equation.label",
22+
defaultMessage: "Inline Equation",
23+
}),
24+
title: defineMessage({
25+
id: "command.format.equation.title",
26+
defaultMessage: "Insert inline LaTeX math equation",
27+
}),
1828
icon: <span>$</span>,
1929
},
2030
display_equation: {
21-
button: "Display",
22-
label: "Displayed Equation",
23-
title: "Insert display LaTeX math equation.",
31+
button: defineMessage({
32+
id: "command.format.display_equation.button",
33+
defaultMessage: "Display",
34+
}),
35+
label: defineMessage({
36+
id: "command.format.display_equation.label",
37+
defaultMessage: "Displayed Equation",
38+
}),
39+
title: defineMessage({
40+
id: "command.format.display_equation.title",
41+
defaultMessage: "Insert display LaTeX math equation",
42+
}),
2443
icon: <span>$$</span>,
2544
},
2645
ai_formula: {
27-
button: "Formula",
28-
label: "AI Generated Formula",
29-
title: "Insert AI generated formula.",
46+
button: defineMessage({
47+
id: "command.format.ai_formula.button",
48+
defaultMessage: "Formula",
49+
}),
50+
label: defineMessage({
51+
id: "command.format.ai_formula.label",
52+
defaultMessage: "AI Generated Formula",
53+
}),
54+
title: defineMessage({
55+
id: "command.format.ai_formula.title",
56+
defaultMessage: "Insert AI generated formula.",
57+
}),
3058
icon: <AIAvatar size={16} />,
3159
},
3260
bold: { icon: "bold", title: "Make selected text bold" },

src/packages/frontend/frame-editors/frame-tree/commands/generic-commands.tsx

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "@cocalc/frontend/frame-editors/generic/chat";
2121
import { get_default_font_size } from "@cocalc/frontend/frame-editors/generic/client";
2222
import { labels, menu } from "@cocalc/frontend/i18n";
23+
import { editor } from "@cocalc/frontend/i18n/common";
2324
import { open_new_tab as openNewTab } from "@cocalc/frontend/misc/open-browser-tab";
2425
import { isSupportedExtension } from "@cocalc/frontend/project/page/home-page/ai-generate-examples";
2526
import { AI_GENERATE_DOC_TAG } from "@cocalc/frontend/project/page/home-page/ai-generate-utils";
@@ -34,7 +35,10 @@ addCommands({
3435
group: "frame-control",
3536
alwaysShow: true,
3637
pos: 1,
37-
title: "Split frame horizontally into two rows",
38+
title: defineMessage({
39+
id: "command.generic.split_row.title",
40+
defaultMessage: "Split frame horizontally into two rows",
41+
}),
3842
onClick: ({ props }) => {
3943
if (props.is_full) {
4044
return props.actions.unset_frame_full();
@@ -43,14 +47,14 @@ addCommands({
4347
}
4448
},
4549
icon: "horizontal-split",
46-
label: "Split Down",
47-
button: "Split",
50+
label: labels.split_frame_horizontally_title,
51+
button: menu.split,
4852
},
4953
"split-col": {
5054
group: "frame-control",
5155
alwaysShow: true,
5256
pos: 2,
53-
title: "Split frame vertically into two columns",
57+
title: labels.split_frame_vertically_title,
5458
onClick: ({ props }) => {
5559
if (props.is_full) {
5660
return props.actions.unset_frame_full();
@@ -59,48 +63,77 @@ addCommands({
5963
}
6064
},
6165
icon: "vertical-split",
62-
label: "Split Right",
63-
button: "Split",
66+
label: defineMessage({
67+
id: "command.generic.split_col.label",
68+
defaultMessage: "Split Right",
69+
description: "Split a frame vertically",
70+
}),
71+
button: menu.split,
6472
},
6573
maximize: {
6674
group: "frame-control",
6775
alwaysShow: true,
6876
pos: 3,
69-
title: "Toggle whether or not this frame is maximized",
77+
title: defineMessage({
78+
id: "command.generic.maximize.title",
79+
defaultMessage: "Toggle whether or not this frame is maximized",
80+
}),
7081
onClick: ({ props }) => {
7182
if (props.is_full) {
7283
props.actions.unset_frame_full();
7384
} else {
7485
props.actions.set_frame_full(props.id);
7586
}
7687
},
77-
label: ({ props }) => {
78-
if (props.is_full) {
79-
return <span>Demaximize Frame</span>;
80-
} else {
81-
return <span>Maximize Frame</span>;
82-
}
83-
},
88+
label: ({ props, intl }) =>
89+
intl.formatMessage(
90+
{
91+
id: "command.generic.maximize.label",
92+
defaultMessage:
93+
"{is_full, select, true {Demaximize Frame} other {Maximize Frame}}",
94+
description:
95+
"Depending on is_full, say maximize or de-maximize frame.",
96+
},
97+
{
98+
is_full: props.is_full,
99+
},
100+
),
84101
icon: "expand",
85102
},
86103
close: {
87104
group: "frame-control",
88105
alwaysShow: true,
89106
pos: 4,
90-
title: "Close this frame. Close all frames to restore the default layout.",
107+
title: defineMessage({
108+
id: "command.generic.close.title",
109+
defaultMessage:
110+
"Close this frame. To restore the default layout, select the application menu entry 'Default Layout'.",
111+
}),
91112
onClick: ({ props }) => {
92113
props.actions.close_frame(props.id);
93114
},
94-
label: "Close Frame",
95-
button: "Close",
115+
label: defineMessage({
116+
id: "command.generic.close.label",
117+
defaultMessage: "Close Frame",
118+
}),
119+
button: defineMessage({
120+
id: "command.generic.close.button",
121+
defaultMessage: "Close",
122+
}),
96123
icon: "times",
97124
},
98125
show_table_of_contents: {
99126
group: "show-frames",
100-
title: "Show the Table of Contents",
127+
title: defineMessage({
128+
id: "command.generic.show_table_of_contents.title",
129+
defaultMessage: "Show the Table of Contents",
130+
}),
101131
icon: "align-right",
102-
label: "Table of Contents",
103-
button: "Contents",
132+
label: editor.table_of_contents_name,
133+
button: defineMessage({
134+
id: "command.generic.show_table_of_contents.button",
135+
defaultMessage: "Contents",
136+
}),
104137
},
105138
guide: {
106139
group: "show-frames",
@@ -352,25 +385,24 @@ addCommands({
352385
kick_other_users_out: {
353386
group: "other-users",
354387
icon: "skull-crossbones",
355-
title:
356-
"Kick all other users out from this document. It will close in all other browsers.",
388+
title: menu.kick_other_users_out_title,
357389
tour: "kick_other_users_out",
358-
label: "Kick Other Users Out",
359-
button: "Kick",
390+
label: menu.kick_other_users_out_label,
391+
button: menu.kick_other_users_out_button,
360392
},
361393

362394
halt_jupyter: {
363395
group: "quit",
364396
icon: "PoweroffOutlined",
365-
label: "Close and Halt...",
366-
button: "Halt",
367-
title: "Halt the running Jupyter kernel and close this notebook.",
397+
label: menu.close_and_halt,
398+
button: menu.halt_jupyter_button,
399+
title: menu.halt_jupyter_title,
368400
},
369401

370402
close_and_halt: {
371403
group: "quit",
372404
icon: "PoweroffOutlined",
373-
label: "Close and Halt...",
405+
label: menu.close_and_halt,
374406
title: "Halt backend server and close this file.",
375407
},
376408

@@ -838,9 +870,18 @@ addCommands({
838870
alwaysShow: true,
839871
icon: "layout",
840872
group: "frame_types",
841-
title: "Reset the layout of all frames to the default",
842-
label: "Default Layout",
843-
button: "Default",
873+
title: defineMessage({
874+
id: "command.generic.reset_local_view_state.title",
875+
defaultMessage: "Reset the layout of all frames to the default",
876+
}),
877+
label: defineMessage({
878+
id: "command.generic.reset_local_view_state.label",
879+
defaultMessage: "Default Layout",
880+
}),
881+
button: defineMessage({
882+
id: "command.generic.reset_local_view_state.button",
883+
defaultMessage: "Default",
884+
}),
844885
},
845886
button_bar: {
846887
alwaysShow: true,

src/packages/frontend/frame-editors/frame-tree/title-bar.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { StandaloneComputeServerDocStatus } from "@cocalc/frontend/compute/stand
3636
import { useStudentProjectFunctionality } from "@cocalc/frontend/course";
3737
import { IS_MOBILE } from "@cocalc/frontend/feature";
3838
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
39+
import { IntlMessage, isIntlMessage, labels } from "@cocalc/frontend/i18n";
3940
import { AIGenerateDocumentModal } from "@cocalc/frontend/project/page/home-page/ai-generate-document";
4041
import { isSupportedExtension } from "@cocalc/frontend/project/page/home-page/ai-generate-examples";
4142
import { AvailableFeatures } from "@cocalc/frontend/project_configuration";
@@ -48,7 +49,6 @@ import {
4849
trunc_middle,
4950
} from "@cocalc/util/misc";
5051
import { COLORS } from "@cocalc/util/theme";
51-
import { isIntlMessage } from "../../i18n";
5252
import { Actions } from "../code-editor/actions";
5353
import { is_safari } from "../generic/browser";
5454
import LanguageModelTitleBarButton from "../llm/title-bar-button";
@@ -406,7 +406,7 @@ export function FrameTitleBar(props: Props) {
406406
return (
407407
<Button
408408
key={"split-row-button"}
409-
title={"Split frame horizontally into two rows"}
409+
title={intl.formatMessage(labels.split_frame_horizontally_title)}
410410
size="small"
411411
type="text"
412412
onClick={(e) => {
@@ -429,7 +429,7 @@ export function FrameTitleBar(props: Props) {
429429
return (
430430
<Button
431431
key={"split-col-button"}
432-
title={"Split frame vertically into two columns"}
432+
title={intl.formatMessage(labels.split_frame_vertically_title)}
433433
size="small"
434434
type="text"
435435
onClick={(e) => {
@@ -912,6 +912,18 @@ export function FrameTitleBar(props: Props) {
912912
);
913913
}
914914

915+
function spec2display(
916+
spec: EditorDescription,
917+
aspect: "name" | "short",
918+
): string {
919+
const label: string | IntlMessage = spec[aspect];
920+
if (isIntlMessage(label)) {
921+
return intl.formatMessage(label);
922+
} else {
923+
return label;
924+
}
925+
}
926+
915927
function renderTitle(): Rendered {
916928
let title: string = "";
917929
if (props.title !== undefined) {
@@ -922,9 +934,9 @@ export function FrameTitleBar(props: Props) {
922934
if (spec != null) {
923935
if (!title) {
924936
if (spec.name) {
925-
title = spec.name;
937+
title = spec2display(spec, "name");
926938
} else if (spec.short) {
927-
title = spec.short;
939+
title = spec2display(spec, "short");
928940
}
929941
}
930942
}

src/packages/frontend/frame-editors/frame-tree/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*/
55

66
import { Map } from "immutable";
7+
78
import { IconName } from "@cocalc/frontend/components/icon";
9+
import { IntlMessage } from "@cocalc/frontend/i18n";
810
import type { Command } from "./commands";
911

1012
export type FrameDirection = "row" | "col";
@@ -35,8 +37,8 @@ export type ConnectionStatus = "disconnected" | "connected" | "connecting";
3537

3638
// Editor spec
3739
export interface EditorDescription {
38-
short: string; // short description of the editor
39-
name: string; // slightly longer description
40+
short: string | IntlMessage; // short description of the editor
41+
name: string | IntlMessage; // slightly longer description
4042
icon: IconName;
4143
component: any; // React component
4244

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { RawIPynb } from "./raw-ipynb";
2828
import { Slideshow } from "./slideshow-revealjs/slideshow";
2929
import { JupyterSnippets } from "./snippets";
3030
import { TableOfContents } from "./table-of-contents";
31+
import { editor } from "@cocalc/frontend/i18n/common";
3132

3233
const {
3334
ICON_NAME: SNIPPET_ICON_NAME,
@@ -100,7 +101,7 @@ export const EDITOR_SPEC = {
100101
} as EditorDescription,
101102
jupyter_table_of_contents: {
102103
short: "Contents",
103-
name: "Table of Contents",
104+
name: editor.table_of_contents_name,
104105
icon: "align-right",
105106
component: TableOfContents,
106107
commands: set(["decrease_font_size", "increase_font_size"]),

src/packages/frontend/frame-editors/latex-editor/editor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
Spec for editing LaTeX documents.
88
*/
99

10+
import { IS_IOS, IS_IPAD } from "@cocalc/frontend/feature";
11+
import { editor } from "@cocalc/frontend/i18n";
1012
import { set } from "@cocalc/util/misc";
11-
import { IS_IOS, IS_IPAD } from "../../feature";
1213
import { CodemirrorEditor } from "../code-editor/codemirror-editor";
1314
import { createEditor } from "../frame-tree/editor";
1415
import { EditorDescription } from "../frame-tree/types";
@@ -150,8 +151,8 @@ const EDITOR_SPEC = {
150151
} as EditorDescription,
151152

152153
latex_table_of_contents: {
153-
short: "Contents",
154-
name: "Table of Contents",
154+
short: editor.table_of_contents_short,
155+
name: editor.table_of_contents_name,
155156
icon: "align-right",
156157
component: TableOfContents,
157158
commands: set(["decrease_font_size", "increase_font_size"]),

src/packages/frontend/frame-editors/markdown-editor/editor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { CodemirrorEditor } from "../code-editor/codemirror-editor";
1717
import { SETTINGS_SPEC } from "../settings/editor";
1818
import { terminal } from "../terminal-editor/editor";
1919
import { time_travel } from "../time-travel-editor/editor";
20+
import { editor } from "../../i18n";
2021

2122
const EDITOR_SPEC = {
2223
slate: {
@@ -118,8 +119,8 @@ const EDITOR_SPEC = {
118119
buttons: set(["edit", "decrease_font_size", "increase_font_size"]),
119120
} as EditorDescription,
120121
markdown_table_of_contents: {
121-
short: "Contents",
122-
name: "Table of Contents",
122+
short: editor.table_of_contents_short,
123+
name: editor.table_of_contents_name,
123124
icon: "align-right",
124125
component: TableOfContents,
125126
commands: set(["decrease_font_size", "increase_font_size"]),

0 commit comments

Comments
 (0)