Skip to content

Commit 193d591

Browse files
authored
Use space.language as source of truth (#3606)
1 parent 1edc5d6 commit 193d591

File tree

20 files changed

+83
-68
lines changed

20 files changed

+83
-68
lines changed

.changeset/chilly-otters-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitbook/colors": patch
3+
---
4+
5+
Fix return type for `colorContrast`

.changeset/red-countries-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Use space language as source of truth for UI locale

packages/colors/src/transformations.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ export function dpsContrast(a: RGBColor, b: RGBColor) {
419419
return contrast < 7.5 ? 0 : contrast;
420420
}
421421

422-
export function colorContrast(background: string, foreground: string[] = [LIGHT_BASE, DARK_BASE]) {
422+
export function colorContrast(
423+
background: string,
424+
foreground: string[] = [LIGHT_BASE, DARK_BASE]
425+
): string {
423426
const bg = hexToRgbArray(background);
424427

425428
const best: { color?: RGBColor; contrast: number } = {
@@ -436,5 +439,5 @@ export function colorContrast(background: string, foreground: string[] = [LIGHT_
436439
}
437440
}
438441

439-
return best.color ? rgbArrayToHex(best.color) : foreground[0];
442+
return best.color ? rgbArrayToHex(best.color) : foreground[0] || LIGHT_BASE;
440443
}

packages/gitbook/src/app/sites/dynamic/[mode]/[siteURL]/[siteData]/(content)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default async function SiteDynamicLayout({
2222
const withTracking = shouldTrackEvents(await headers());
2323

2424
return (
25-
<CustomizationRootLayout forcedTheme={forcedTheme} customization={context.customization}>
25+
<CustomizationRootLayout forcedTheme={forcedTheme} context={context}>
2626
<SiteLayout
2727
context={context}
2828
forcedTheme={forcedTheme}

packages/gitbook/src/app/sites/static/[mode]/[siteURL]/[siteData]/(content)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default async function SiteStaticLayout({
1919
const withTracking = shouldTrackEvents();
2020

2121
return (
22-
<CustomizationRootLayout customization={context.customization}>
22+
<CustomizationRootLayout context={context}>
2323
<SiteLayout
2424
context={context}
2525
withTracking={withTracking}

packages/gitbook/src/components/AI/server-actions/AIToolCallsSummary.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function DescriptionForPageContentToolCall(props: {
7272
}) {
7373
const { toolCall, context } = props;
7474

75-
const language = getSpaceLanguage(context.customization);
75+
const language = getSpaceLanguage(context);
7676

7777
return (
7878
<p>
@@ -102,7 +102,7 @@ function DescriptionForMCPToolCall(props: {
102102
}) {
103103
const { toolCall, context } = props;
104104

105-
const language = getSpaceLanguage(context.customization);
105+
const language = getSpaceLanguage(context);
106106

107107
return (
108108
<p>
@@ -130,7 +130,7 @@ async function DescriptionForSearchToolCall(props: {
130130
}) {
131131
const { toolCall, context } = props;
132132

133-
const language = getSpaceLanguage(context.customization);
133+
const language = getSpaceLanguage(context);
134134

135135
// Resolve all hrefs for search results in parallel
136136
const searchResultsWithHrefs = await Promise.all(
@@ -241,7 +241,7 @@ function DescriptionForGetPagesToolCall(props: {
241241
}) {
242242
const { toolCall, context } = props;
243243

244-
const language = getSpaceLanguage(context.customization);
244+
const language = getSpaceLanguage(context);
245245

246246
return (
247247
<p>

packages/gitbook/src/components/DocumentView/InlineLink/InlineLink.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ export async function InlineLink(props: InlineProps<DocumentInlineLink>) {
2020
: null;
2121
const { contentContext } = context;
2222

23-
const language =
24-
contentContext && 'customization' in contentContext
25-
? getSpaceLanguage(contentContext.customization)
26-
: languages.en;
23+
const language = contentContext ? getSpaceLanguage(contentContext) : languages.en;
2724

2825
if (!contentContext || !resolved) {
2926
return (

packages/gitbook/src/components/DocumentView/OpenAPI/context.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Heading } from '../Heading';
1111

1212
import './scalar.css';
1313
import './style.css';
14-
import { DEFAULT_LOCALE, getCustomizationLocale } from '@/intl/server';
14+
import { DEFAULT_LOCALE, getSpaceLocale } from '@/intl/server';
1515
import type { GitBookAnyContext } from '@/lib/context';
1616
import type {
1717
AnyOpenAPIOperationsBlock,
@@ -30,10 +30,7 @@ export function getOpenAPIContext(args: {
3030
const { props, specUrl, context } = args;
3131
const { block } = props;
3232

33-
const customization = context && 'customization' in context ? context.customization : null;
34-
const customizationLocale = customization
35-
? getCustomizationLocale(customization)
36-
: DEFAULT_LOCALE;
33+
const customizationLocale = context ? getSpaceLocale(context) : DEFAULT_LOCALE;
3734
const locale = checkIsValidLocale(customizationLocale) ? customizationLocale : DEFAULT_LOCALE;
3835

3936
return {

packages/gitbook/src/components/Embeddable/EmbeddableRootLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function EmbeddableRootLayout({
2121
children,
2222
}: React.PropsWithChildren<EmbeddableRootLayoutProps>) {
2323
return (
24-
<CustomizationRootLayout customization={context.customization}>
24+
<CustomizationRootLayout context={context}>
2525
<SiteLayoutClientContexts
2626
forcedTheme={context.customization.themes.default}
2727
externalLinksTarget={context.customization.externalLinks.target}

packages/gitbook/src/components/Header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function Header(props: {
138138
);
139139
})}
140140
<HeaderLinkMore
141-
label={t(getSpaceLanguage(customization), 'more')}
141+
label={t(getSpaceLanguage(context), 'more')}
142142
links={customization.header.links}
143143
context={context}
144144
/>

0 commit comments

Comments
 (0)