Skip to content

Commit 4589f27

Browse files
committed
feat: translate strings from a11ycloud
1 parent e3199e9 commit 4589f27

File tree

12 files changed

+32
-34
lines changed

12 files changed

+32
-34
lines changed

src/components/App/HeadMetaTags.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { encode } from "js-base64";
33
import Head from "next/head";
44
import { useAppContext } from "../../lib/context/AppContext";
55
import useHostnameContext from "../../lib/context/HostnameContext";
6-
import { translatedStringFromObject } from "../../lib/i18n/translatedStringFromObject";
6+
import { useTranslatedStringFromObject } from "../../lib/i18n/useTranslatedStringFromObject";
77
import { getProductTitle } from "../../lib/model/ac/ClientSideConfiguration";
88
import FacebookMeta from "./FacebookMeta";
99
import OpenGraph from "./OpenGraph";
@@ -17,8 +17,8 @@ export default function HeadMetaTags() {
1717
description: undefined,
1818
};
1919
const { twitter, facebook } = meta || {};
20-
const translatedDescription = translatedStringFromObject(description);
21-
const translatedProductName = translatedStringFromObject(productName);
20+
const translatedDescription = useTranslatedStringFromObject(description);
21+
const translatedProductName = useTranslatedStringFromObject(productName);
2222
const pageTitle = translatedProductName;
2323
const facebookMetaData = { ...facebook, imageWidth: 0, imageHeight: 0 };
2424
const hostName = useHostnameContext();
@@ -53,7 +53,7 @@ export default function HeadMetaTags() {
5353

5454
{/* Misc */}
5555
<meta
56-
content={translatedStringFromObject(description)}
56+
content={useTranslatedStringFromObject(description)}
5757
name="description"
5858
key="description"
5959
/>

src/components/CombinedFeaturePanel/components/AccessibilitySection/PlaceAccessibility/AccessibilityDetailsTree.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import isPlainObject from "lodash/isPlainObject";
55
import * as React from "react";
66
import { type FC, Fragment } from "react";
77
import styled from "styled-components";
8-
import { translatedStringFromObject } from "../../../../../lib/i18n/translatedStringFromObject";
8+
import { useTranslatedStringFromObject } from "../../../../../lib/i18n/useTranslatedStringFromObject";
99
import type IAccessibilityAttribute from "../../../../../lib/model/ac/IAccessibilityAttribute";
1010
import { cx } from "../../../../../lib/util/cx";
1111

@@ -26,7 +26,9 @@ const formatName = (
2626
): string => {
2727
const string =
2828
(accessibilityAttributes &&
29-
translatedStringFromObject(accessibilityAttributes.get(name)?.label)) ||
29+
useTranslatedStringFromObject(
30+
accessibilityAttributes.get(name)?.label,
31+
)) ||
3032
humanizeString(name);
3133
return string.replace(/^Rating /, "");
3234
};

src/components/MappingEvents/MappingEventMetadata.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Head from "next/head";
22
import { useAppContext } from "../../lib/context/AppContext";
33
import useHostnameContext from "../../lib/context/HostnameContext";
4-
import { translatedStringFromObject } from "../../lib/i18n/translatedStringFromObject";
4+
import { useTranslatedStringFromObject } from "../../lib/i18n/useTranslatedStringFromObject";
55
import { buildFullImageUrl } from "../../lib/model/ac/Image";
66
import type { MappingEvent } from "../../lib/model/ac/MappingEvent";
77
import FacebookMeta from "../App/FacebookMeta";
@@ -14,7 +14,7 @@ export function MappingEventMetadata({
1414
const { clientSideConfiguration } = useAppContext();
1515
const productName =
1616
clientSideConfiguration?.textContent?.product?.name || "Wheelmap";
17-
const translatedProductName = translatedStringFromObject(productName);
17+
const translatedProductName = useTranslatedStringFromObject(productName);
1818

1919
const pageTitle = translatedProductName
2020
? `${mappingEvent.name} - ${translatedProductName}`

src/components/NodeToolbar/Equipment/getEquipmentInfoDescription.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { EquipmentInfo } from "@sozialhelden/a11yjson";
22
import type { LocalizedString } from "../../../lib/i18n/LocalizedString";
3-
import { translatedStringFromObject } from "../../../lib/i18n/translatedStringFromObject";
3+
import { useTranslatedStringFromObject } from "../../../lib/i18n/useTranslatedStringFromObject";
44

55
export default function getEquipmentInfoDescription(
66
equipmentInfo: EquipmentInfo | null | undefined,
@@ -24,5 +24,5 @@ export default function getEquipmentInfoDescription(
2424
break;
2525
}
2626
}
27-
return description && translatedStringFromObject(description);
27+
return description && useTranslatedStringFromObject(description);
2828
}

src/components/Onboarding/OnboardingStep.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { t } from "@transifex/native";
1313
import * as React from "react";
1414
import { useEffect } from "react";
1515
import { AppContext } from "../../lib/context/AppContext";
16-
import { translatedStringFromObject } from "../../lib/i18n/translatedStringFromObject";
16+
import { useTranslatedStringFromObject } from "../../lib/i18n/useTranslatedStringFromObject";
1717
import type { YesNoLimitedUnknown } from "../../lib/model/ac/Feature";
1818
import {
1919
accessibilityColor as accessibilityColorName,
@@ -29,7 +29,7 @@ export const OnboardingStep: React.FC<{
2929
onClose?: () => unknown;
3030
}> = ({ onClose = () => {} }) => {
3131
const { clientSideConfiguration } = React.useContext(AppContext) ?? {};
32-
const headerMarkdown = translatedStringFromObject(
32+
const headerMarkdown = useTranslatedStringFromObject(
3333
clientSideConfiguration?.textContent?.onboarding?.headerMarkdown,
3434
);
3535

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { t } from "@transifex/native";
2-
import { translatedStringFromObject } from "../../lib/i18n/translatedStringFromObject";
2+
import { useTranslatedStringFromObject } from "../../lib/i18n/useTranslatedStringFromObject";
33

44
// select a white label product name
55
export const getProductName = (
66
clientSideConfiguration: ClientSideConfiguration | undefined,
77
) =>
8-
translatedStringFromObject(
8+
useTranslatedStringFromObject(
99
clientSideConfiguration?.textContent?.product?.name,
1010
) || "Wheelmap";

src/components/TopBar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, Flex, Text } from "@radix-ui/themes";
22
import styled from "styled-components";
33
import NeedsPicker from "~/domains/needs/components/NeedsPicker";
4-
import { translatedStringFromObject } from "~/lib/i18n/translatedStringFromObject";
4+
import { useTranslatedStringFromObject } from "~/lib/i18n/useTranslatedStringFromObject";
55
import type { ClientSideConfiguration } from "~/lib/model/ac/ClientSideConfiguration";
66
import Logo from "./TopBar/Logo";
77
import Navigation from "./TopBar/Navigation";
@@ -29,7 +29,7 @@ export default function TopBar({
2929
}: {
3030
clientSideConfiguration: ClientSideConfiguration;
3131
}) {
32-
const claim = translatedStringFromObject(textContent?.product?.claim);
32+
const claim = useTranslatedStringFromObject(textContent?.product?.claim);
3333

3434
return (
3535
<StyledTopBar role="banner">

src/components/TopBar/Navigation/AppLink.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export default function AppLink({
5050
Element = ErroneousLink;
5151
}
5252

53+
console.log("Element", label);
54+
5355
return (
5456
Element && (
5557
<Element {...{ label, badgeLabel, url, asMenuItem, buttonProps }} />

src/lib/i18n/translatedStringFromObject.ts src/lib/i18n/useTranslatedStringFromObject.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import compact from "lodash/compact";
22
import uniq from "lodash/uniq";
3+
import { useCurrentLanguageTagStrings } from "~/lib/context/LanguageTagContext";
34
import type { LocalizedString } from "./LocalizedString";
4-
import { currentLocales } from "./i18n";
55
import { normalizeLanguageCode } from "./normalizeLanguageCode";
66

7-
export function translatedStringFromObject(
7+
export function useTranslatedStringFromObject(
88
string: LocalizedString | null | undefined,
99
): string | undefined {
1010
if (typeof string === "undefined" || string === null) {
@@ -15,9 +15,7 @@ export function translatedStringFromObject(
1515
if (typeof string === "object") {
1616
const firstAvailableLocale = Object.keys(string)[0];
1717

18-
const normalizedRequestedLanguageTags = currentLocales.map(
19-
(locale) => locale.transifexLanguageIdentifier,
20-
);
18+
const normalizedRequestedLanguageTags = useCurrentLanguageTagStrings();
2119

2220
const normalizedLanguageTags = normalizedRequestedLanguageTags.map(
2321
normalizeLanguageCode,

src/lib/model/ac/ClientSideConfiguration.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LocalizedString } from "@sozialhelden/a11yjson";
2-
import { translatedStringFromObject } from "../../i18n/translatedStringFromObject";
2+
import { useTranslatedStringFromObject } from "../../i18n/useTranslatedStringFromObject";
33
import type { IBranding } from "./IBranding";
44

55
export interface TwitterConfiguration {
@@ -64,10 +64,10 @@ export function getProductTitle(
6464
const { name, claim } = product;
6565

6666
if (!title) {
67-
return `${translatedStringFromObject(name)}${translatedStringFromObject(
67+
return `${useTranslatedStringFromObject(name)}${useTranslatedStringFromObject(
6868
claim,
6969
)}`;
7070
}
7171

72-
return `${title}${translatedStringFromObject(name)}`;
72+
return `${title}${useTranslatedStringFromObject(name)}`;
7373
}

src/lib/useAppLink.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { translatedStringFromObject } from "~/lib/i18n/translatedStringFromObject";
1+
import { useTranslatedStringFromObject } from "~/lib/i18n/useTranslatedStringFromObject";
22
import type { IApp } from "~/lib/model/ac/App";
33
import type IAppLink from "~/lib/model/ac/IAppLink";
44
import type { MappingEvent } from "~/lib/model/ac/MappingEvent";
@@ -11,9 +11,9 @@ export function useAppLink(
1111
joinedMappingEvent?: MappingEvent,
1212
) {
1313
const baseUrl = `https://${app._id}/`;
14-
const localizedUrl = translatedStringFromObject(link.url);
15-
const label = translatedStringFromObject(link.label);
16-
const badgeLabel = translatedStringFromObject(link.badgeLabel);
14+
const localizedUrl = useTranslatedStringFromObject(link.url);
15+
const label = useTranslatedStringFromObject(link.label);
16+
const badgeLabel = useTranslatedStringFromObject(link.badgeLabel);
1717
const isExternal = localizedUrl?.startsWith("http");
1818

1919
/** Insert values of template variables into the link's URL */

src/lib/useNavigation.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ export function useNavigation() {
2323
const app = useAppContext();
2424
const appLinks = app.related?.appLinks;
2525
const uniqueSurveyId = useUniqueSurveyId();
26-
const translatedAppLinks = React.useMemo(
27-
() =>
28-
Object.values(appLinks ?? {}).map((link) =>
29-
useAppLink(link, app, uniqueSurveyId, joinedMappingEvent),
30-
),
31-
[app, appLinks, joinedMappingEvent, uniqueSurveyId],
26+
const translatedAppLinks = Object.values(appLinks ?? {}).map((link) =>
27+
useAppLink(link, app, uniqueSurveyId, joinedMappingEvent),
3228
);
3329

3430
return React.useMemo(() => {

0 commit comments

Comments
 (0)