Skip to content

Commit e08807b

Browse files
committed
frontend/i18n: fixing the "compilation" step; catching up with spanish and chinese, expanding coverage, ...
1 parent bb2555d commit e08807b

File tree

32 files changed

+6674
-384
lines changed

32 files changed

+6674
-384
lines changed

src/packages/frontend/account/settings/account-settings.tsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Alert as AntdAlert, Space } from "antd";
77
import { List, Map } from "immutable";
88
import { join } from "path";
9-
import { useIntl } from "react-intl";
9+
import { FormattedMessage, useIntl } from "react-intl";
1010

1111
import {
1212
Alert,
@@ -475,7 +475,12 @@ export function AccountSettings(props: Readonly<Props>) {
475475
}
476476
return (
477477
<Row style={{ marginBottom: "15px" }}>
478-
<Col md={4}>Created</Col>
478+
<Col md={4}>
479+
<FormattedMessage
480+
id="account.settings.created.label"
481+
defaultMessage={"Created"}
482+
/>
483+
</Col>
479484
<Col md={8}>
480485
<TimeAgo date={props.created} />
481486
</Col>
@@ -505,7 +510,10 @@ export function AccountSettings(props: Readonly<Props>) {
505510
disabled={props.is_anonymous && !terms_checkbox}
506511
/>
507512
<TextSetting
508-
label="Username (optional)"
513+
label={intl.formatMessage({
514+
id: "account.settings.username.label",
515+
defaultMessage: "Username (optional)",
516+
})}
509517
value={props.name}
510518
onChange={(e) => {
511519
const name = e.target.value?.trim();
@@ -535,16 +543,16 @@ export function AccountSettings(props: Readonly<Props>) {
535543
showIcon
536544
style={{ margin: "15px 0" }}
537545
message={
538-
<>
539-
Setting a username provides optional nicer URL's for shared
540-
public documents. Your username can be between 1 and 39
541-
characters, contain upper and lower case letters, numbers, and
542-
dashes.
543-
<br />
544-
WARNING: If you change your username, existing links using the
545-
previous username will no longer work (automatic redirects are
546-
not implemented), so change with caution.
547-
</>
546+
<FormattedMessage
547+
id="account.settings.username.info"
548+
defaultMessage={`Setting a username provides optional nicer URL's for shared
549+
public documents. Your username can be between 1 and 39 characters,
550+
contain upper and lower case letters, numbers, and dashes.
551+
{br}
552+
WARNING: If you change your username, existing links using the previous username
553+
will no longer work (automatic redirects are not implemented), so change with caution.`}
554+
values={{ br: <br /> }}
555+
/>
548556
}
549557
type="info"
550558
/>
@@ -579,7 +587,12 @@ export function AccountSettings(props: Readonly<Props>) {
579587
actions().set_account_table({ unlisted: e.target.checked })
580588
}
581589
>
582-
Unlisted: you can only be found by an exact email address match
590+
<FormattedMessage
591+
id="account.settings.unlisted.label"
592+
defaultMessage={
593+
"Unlisted: you can only be found by an exact email address match"
594+
}
595+
/>
583596
</Checkbox>
584597
);
585598
}

src/packages/frontend/app/localize.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ConfigProvider as AntdConfigProvider } from "antd";
77
import type { Locale as AntdLocale } from "antd/lib/locale";
88
import enUS from "antd/locale/en_US";
99
import { isEmpty } from "lodash";
10-
import { createContext, useContext, useState } from "react";
10+
import { createContext, useContext, useRef, useState } from "react";
1111
import { IntlProvider } from "react-intl";
1212
import useAsyncEffect from "use-async-effect";
1313

@@ -43,6 +43,14 @@ export function Localize({ children }: { children: React.ReactNode }) {
4343
const [antdLoc, setAntdLoc] = useState<AntdLocale | undefined>(undefined);
4444
const [messages, setMessages] = useState<Messages | undefined>(undefined);
4545
const { antdTheme } = useAntdStyleProvider();
46+
const uniqueKey = useRef<{ [tag: string]: number }>({});
47+
48+
// Note: this is e.g. necessary to render text in a modal, where some caching happens, apparently
49+
function getKey(tag: string): number {
50+
const n = (uniqueKey.current[tag] ?? 0) + 1;
51+
uniqueKey.current[tag] = n;
52+
return n;
53+
}
4654

4755
useAsyncEffect(async () => {
4856
setMessages(await loadLocaleMessages(locale));
@@ -92,12 +100,20 @@ export function Localize({ children }: { children: React.ReactNode }) {
92100
defaultLocale={DEFAULT_LOCALE}
93101
onError={onError}
94102
defaultRichTextElements={{
95-
b: (ch) => <Text strong>{ch}</Text>,
96-
p: (ch) => <Paragraph>{ch}</Paragraph>,
97-
code: (ch) => <Text code>{ch}</Text>,
98-
ul: (e) => <ul>{e}</ul>,
99-
ol: (e) => <ol>{e}</ol>,
100-
li: (e) => <li>{e}</li>,
103+
b: (ch) => (
104+
<Text strong key={getKey("b")}>
105+
{ch}
106+
</Text>
107+
),
108+
p: (ch) => <Paragraph key={getKey("p")}>{ch}</Paragraph>,
109+
code: (ch) => (
110+
<Text code key={getKey("code")}>
111+
{ch}
112+
</Text>
113+
),
114+
ul: (e) => <ul key={getKey("ul")}>{e}</ul>,
115+
ol: (e) => <ol key={getKey("ol")}>{e}</ol>,
116+
li: (e) => <li key={getKey("li")}>{e}</li>,
101117
}}
102118
>
103119
{renderApp()}

src/packages/frontend/editors/stopwatch/button-bar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ Some buttons
88
*/
99
import { HistoryOutlined, RedoOutlined, UndoOutlined } from "@ant-design/icons";
1010
import { Button } from "antd";
11+
import { useIntl } from "react-intl";
1112

1213
import { Rendered } from "@cocalc/frontend/app-framework";
1314
import { Gap } from "@cocalc/frontend/components/gap";
15+
import { labels } from "@cocalc/frontend/i18n";
1416
import { TimeActions } from "./actions";
1517

1618
export function ButtonBar({ actions }: { actions: TimeActions }): JSX.Element {
@@ -24,13 +26,15 @@ export function ButtonBar({ actions }: { actions: TimeActions }): JSX.Element {
2426
}
2527

2628
function timeTravelButton(actions: TimeActions): Rendered {
29+
const intl = useIntl();
30+
2731
return (
2832
<Button
2933
key={"time-travel"}
3034
onClick={() => actions.time_travel()}
3135
icon={<HistoryOutlined />}
3236
>
33-
TimeTravel
37+
{intl.formatMessage(labels.timetravel)}
3438
</Button>
3539
);
3640
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const SEARCH_COMMANDS = "search_commands";
22
export const APPLICATION_MENU = "__title__";
3-
export const AI_GEN_TEXT = "Help me write...";
3+

src/packages/frontend/frame-editors/frame-tree/commands/editor-menus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { Command, Menus } from "./types";
1616
type Command0 = {
1717
icon?: string;
1818
iconRotate?: IconRotation;
19-
label?: string | (({ props }: any) => any);
19+
label?: string | (({ props }: any) => any) | IntlMessage;
2020
name?: string;
2121
children?;
2222
disabled?: ({ props }: { props: any }) => boolean;

0 commit comments

Comments
 (0)