diff --git a/astro/src/components/Alert/Alert.astro b/astro/src/components/Alert/Alert.astro index a43bfba6733..d856424674d 100644 --- a/astro/src/components/Alert/Alert.astro +++ b/astro/src/components/Alert/Alert.astro @@ -1,23 +1,20 @@ --- import styles from "./Alert.module.css"; import { classListFactory } from "@lib/cssUtils/classListFactory"; -import { i18n } from "@lib/i18n/i18n"; -import { DEFAULT_LOCALE, isLocale } from "@lib/i18n/locale"; +import { useTranslations } from "@lib/i18n/i18n"; interface Props { level?: "info" | "danger" | "warning" | "tip"; } const { level = "info" } = Astro.props; -const lang = isLocale(Astro.currentLocale) - ? Astro.currentLocale - : DEFAULT_LOCALE; +const translate = useTranslations(Astro.currentLocale); const labels: Record, string> = { - info: i18n("alert_note", lang), - danger: i18n("alert_caution", lang), - warning: i18n("alert_warning", lang), - tip: i18n("alert_tip", lang), + info: translate("alert_note"), + danger: translate("alert_caution"), + warning: translate("alert_warning"), + tip: translate("alert_tip"), }; const label = labels[level]; diff --git a/astro/src/components/ApiCodeExample/ApiCodeExample.astro b/astro/src/components/ApiCodeExample/ApiCodeExample.astro index f916933fc23..eae0ceffcac 100644 --- a/astro/src/components/ApiCodeExample/ApiCodeExample.astro +++ b/astro/src/components/ApiCodeExample/ApiCodeExample.astro @@ -6,7 +6,7 @@ import ExpandChevron from "@components/ExpandChevron/ExpandChevron.astro"; import styles from "./ApiCodeExample.module.css"; import { classListFactory } from "@lib/cssUtils/classListFactory"; import { generateElementId } from "@lib/componentUtils/generateElementId"; -import { i18n } from "@lib/i18n/i18n"; +import { useTranslations } from "@lib/i18n/i18n"; const cl = classListFactory(styles); @@ -29,6 +29,7 @@ interface Props { } const { examples } = Astro.props; +const translate = useTranslations(Astro.currentLocale); const groupId = generateElementId("api-code-example"); const labels = examples.map((ex) => ex.label); @@ -38,7 +39,7 @@ const panelIds = examples.map((_, i) => `${groupId}-panel-${i}`); { examples.length > 0 && (
-

{i18n("code_example")}

+

{translate("code_example")}

{examples.map((ex, tabIdx) => ( diff --git a/astro/src/components/ApiEndpoint/ApiEndpoint.astro b/astro/src/components/ApiEndpoint/ApiEndpoint.astro index ea1c18c409c..2cf3fa801fc 100644 --- a/astro/src/components/ApiEndpoint/ApiEndpoint.astro +++ b/astro/src/components/ApiEndpoint/ApiEndpoint.astro @@ -12,7 +12,7 @@ import { getDefaultRegions } from "@lib/api/regionResolver"; import { renderMarkdownInline } from "@lib/api/markdownRenderer"; import styles from "./ApiEndpoint.module.css"; import { classListFactory } from "@lib/cssUtils/classListFactory"; -import { i18n } from "@lib/i18n/i18n"; +import { useTranslations } from "@lib/i18n/i18n"; const allRegions = getDefaultRegions(); const cl = classListFactory(styles); @@ -50,6 +50,7 @@ interface Props { } const { data: dataJson } = Astro.props; +const translate = useTranslations(Astro.currentLocale); let ep: EndpointData | null = null; try { @@ -122,7 +123,7 @@ const hasParams =
{/* Description — rendered as slot content from the parent page */} - {ep.description &&

{i18n("overview")}

} + {ep.description &&

{translate("overview")}

} {/* Permissions */} @@ -146,7 +147,7 @@ const hasParams = {/* Arguments */} {hasParams && (
-

{i18n("arguments")}

+

{translate("arguments")}

{ep.pathParams && ep.pathParams.length > 0 && ( )} diff --git a/astro/src/components/ApiPageHeader/ApiPageHeader.astro b/astro/src/components/ApiPageHeader/ApiPageHeader.astro index c919bf30a3c..10dc8bcd7bc 100644 --- a/astro/src/components/ApiPageHeader/ApiPageHeader.astro +++ b/astro/src/components/ApiPageHeader/ApiPageHeader.astro @@ -1,22 +1,20 @@ --- import CopyPageButtonIsland from "@components/CopyPageButton/CopyPageButtonIsland.astro"; import { classListFactory } from "@lib/cssUtils/classListFactory"; -import type { Locale } from "@lib/i18n/locale"; import styles from "./ApiPageHeader.module.css"; const cl = classListFactory(styles); interface Props { title: string; - lang: Locale; } -const { title, lang } = Astro.props; +const { title } = Astro.props; ---

{title}

- +
diff --git a/astro/src/components/ApiResponse/ApiResponse.astro b/astro/src/components/ApiResponse/ApiResponse.astro index c9ccc7b374d..4f2e6a99640 100644 --- a/astro/src/components/ApiResponse/ApiResponse.astro +++ b/astro/src/components/ApiResponse/ApiResponse.astro @@ -8,7 +8,7 @@ import { renderMarkdownInline } from "@lib/api/markdownRenderer"; import styles from "./ApiResponse.module.css"; import { classListFactory } from "@lib/cssUtils/classListFactory"; import { generateElementId } from "@lib/componentUtils/generateElementId"; -import { i18n } from "@lib/i18n/i18n"; +import { useTranslations } from "@lib/i18n/i18n"; const cl = classListFactory(styles); @@ -29,6 +29,7 @@ interface Props { } const { responses } = Astro.props; +const translate = useTranslations(Astro.currentLocale); const outerGroupId = generateElementId("api-response"); const outerLabels = responses.map((r) => r.statusCode); @@ -42,7 +43,7 @@ const innerPanelIds = responses.map((_, i) => [ { responses.length > 0 && (
-

{i18n("response")}

+

{translate("response")}

[ diff --git a/astro/src/components/ApiSchemaTable/ApiSchemaTable.astro b/astro/src/components/ApiSchemaTable/ApiSchemaTable.astro index 278810b8273..a6e9026ff08 100644 --- a/astro/src/components/ApiSchemaTable/ApiSchemaTable.astro +++ b/astro/src/components/ApiSchemaTable/ApiSchemaTable.astro @@ -5,7 +5,7 @@ import SchemaFieldRow from "./SchemaFieldRow.astro"; import styles from "./ApiSchemaTable.module.css"; import { classListFactory } from "@lib/cssUtils/classListFactory"; import { generateElementId } from "@lib/componentUtils/generateElementId"; -import { i18n } from "@lib/i18n/i18n"; +import { useTranslations } from "@lib/i18n/i18n"; const cl = classListFactory(styles); @@ -16,6 +16,7 @@ interface Props { } const { fields, title, showExpandAll = true } = Astro.props; +const translate = useTranslations(Astro.currentLocale); const tableId = generateElementId("schema-table"); const expandAllId = `${tableId}-expand-all`; @@ -63,10 +64,10 @@ const showToolbar = showExpandAll && anyExpandable; }
-
{i18n("name")}
{" "} -
{i18n("type")}
{" "} +
{translate("name")}
{" "} +
{translate("type")}
{" "}
- {i18n("description")} + {translate("description")}
{fields.map((field) => )} diff --git a/astro/src/components/ApiSideNav/ApiSideNav.astro b/astro/src/components/ApiSideNav/ApiSideNav.astro index 9864b55e1c5..284ebc84a29 100644 --- a/astro/src/components/ApiSideNav/ApiSideNav.astro +++ b/astro/src/components/ApiSideNav/ApiSideNav.astro @@ -5,7 +5,8 @@ import { classListFactory } from "@lib/cssUtils/classListFactory"; import SearchBar, { type SearchBarLabels, } from "@components/SearchBar/SearchBar"; -import { DEFAULT_LOCALE, localizedHref, type Locale } from "@lib/i18n/locale"; +import { localizedHref, resolveLocale } from "@lib/i18n/locale"; +import { useTranslations } from "@lib/i18n/i18n"; import ScrollActiveIntoView from "@components/ScrollActiveIntoView/ScrollActiveIntoView.astro"; import type { OverviewPage } from "@lib/api/overviewPages"; @@ -16,7 +17,6 @@ interface Props { overviewPages?: OverviewPage[]; isOverviewSection?: boolean; activeOverviewPageSlug?: string; - lang?: Locale; } const { @@ -26,11 +26,13 @@ const { overviewPages = [], isOverviewSection = false, activeOverviewPageSlug, - lang = DEFAULT_LOCALE, } = Astro.props; +// `lang` is still needed for the hrefs below; `translate` covers the labels. +const lang = resolveLocale(Astro.currentLocale); +const translate = useTranslations(lang); const cl = classListFactory(styles); -const overviewLabel = "Overview"; +const overviewLabel = translate("overview"); const overviewHref = localizedHref(lang, "/api/latest/"); // TODO: replace hardcoded English with i18n() once authoritative translation @@ -45,7 +47,7 @@ const searchLabels: SearchBarLabels = {