Skip to content

Commit

Permalink
Use translation for "Sponsored via GitBook" (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Sep 17, 2024
1 parent ef9d012 commit bfbed1a
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-turtles-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gitbook': patch
---

Ensure "Sponsored via GitBook" can be translated in all languages
38 changes: 35 additions & 3 deletions packages/gitbook/src/components/Ads/Ad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from 'react';

import { t, useLanguage } from '@/intl/client';
import { ClassValue, tcls } from '@/lib/tailwind';

import { renderAd } from './renderAd';
Expand Down Expand Up @@ -78,7 +79,6 @@ export function Ad({

(async () => {
const result = await renderAd({
spaceId,
placement,
ignore: ignore || preview,
zoneId: realZoneId,
Expand All @@ -97,7 +97,7 @@ export function Ad({
return () => {
cancelled = true;
};
}, [visible, spaceId, zoneId, ignore, placement, mode]);
}, [visible, zoneId, ignore, placement, mode]);

const viaUrl = new URL('https://www.gitbook.com');
viaUrl.searchParams.set('utm_source', 'content');
Expand All @@ -106,7 +106,39 @@ export function Ad({

return (
<div ref={containerRef} className={tcls(style)}>
{ad ? ad : null}
{ad ? (
<>
{ad}
<AdSponsoredLink spaceId={spaceId} />
</>
) : null}
</div>
);
}

function AdSponsoredLink(props: { spaceId: string }) {
const { spaceId } = props;
const language = useLanguage();

const viaUrl = new URL('https://www.gitbook.com');
viaUrl.searchParams.set('utm_source', 'content');
viaUrl.searchParams.set('utm_medium', 'sponsoring');
viaUrl.searchParams.set('utm_campaign', spaceId);

return (
<p
className={tcls(
'mt-2',
'mr-2',
'text-xs',
'text-right',
'text-dark/5',
'dark:text-light/5',
)}
>
<a target="_blank" href={viaUrl.toString()} className={tcls('hover:underline')}>
{t(language, 'sponsored_via_gitbook')}
</a>
</p>
);
}
28 changes: 2 additions & 26 deletions packages/gitbook/src/components/Ads/renderAd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import { headers } from 'next/headers';

import { tcls } from '@/lib/tailwind';

import { AdClassicRendering } from './AdClassicRendering';
import { AdCoverRendering } from './AdCoverRendering';
import { AdPixels } from './AdPixels';
Expand All @@ -12,8 +10,6 @@ import { AdItem, AdsResponse } from './types';
interface FetchAdOptions {
/** ID of the zone to fetch Ads for */
zoneId: string;
/** ID of the space */
spaceId: string;
/** Mode to render the Ad */
mode: 'classic' | 'auto' | 'cover';
/** Name of the placement for the ad */
Expand All @@ -28,18 +24,13 @@ interface FetchAdOptions {
* and properly access user-agent and IP.
*/
export async function renderAd(options: FetchAdOptions) {
const { spaceId, mode } = options;
const { mode } = options;
const result = await fetchAd(options);
if (!result || !result.ad.description || !result.ad.statlink) {
return null;
}

const { ad, ip } = result;

const viaUrl = new URL('https://www.gitbook.com');
viaUrl.searchParams.set('utm_source', 'content');
viaUrl.searchParams.set('utm_medium', 'ads');
viaUrl.searchParams.set('utm_campaign', spaceId);
const { ad } = result;

return (
<>
Expand All @@ -49,21 +40,6 @@ export async function renderAd(options: FetchAdOptions) {
<AdCoverRendering ad={ad} />
)}
{ad.pixel ? <AdPixels rawPixel={ad.pixel} /> : null}
<p
className={tcls(
'mt-2',
'mr-2',
'text-xs',
'text-right',
'text-dark/5',
'dark:text-light/5',
)}
data-debug-ip={ip}
>
<a target="_blank" href={viaUrl.toString()} className={tcls('hover:underline')}>
Sponsored via GitBook
</a>
</p>
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/de.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const de = {
locale: 'de',
powered_by_gitbook: 'Bereitgestellt von GitBook',
sponsored_via_gitbook: 'Gesponsert von GitBook',
switch_to_dark_theme: 'Zum dunklen Modus wechseln',
switch_to_light_theme: 'Zum hellen Modus wechseln',
switch_to_system_theme: 'Zum Systemmodus wechseln',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/en.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const en = {
locale: 'en',
powered_by_gitbook: 'Powered by GitBook',
sponsored_via_gitbook: 'Sponsored via GitBook',
switch_to_dark_theme: 'Switch to dark theme',
switch_to_light_theme: 'Switch to light theme',
switch_to_system_theme: 'Switch to system theme',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TranslationLanguage } from './types';
export const es: TranslationLanguage = {
locale: 'es',
powered_by_gitbook: 'Con tecnología de GitBook',
sponsored_via_gitbook: 'Patrocinado por GitBook',
switch_to_dark_theme: 'Cambiar a tema oscuro',
switch_to_light_theme: 'Cambiar a tema claro',
switch_to_system_theme: 'Cambiar a tema del sistema',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TranslationLanguage } from './types';
export const fr: TranslationLanguage = {
locale: 'fr',
powered_by_gitbook: 'Propulsé par GitBook',
sponsored_via_gitbook: 'Sponsorisé avec GitBook',
switch_to_dark_theme: 'Passer au thème sombre',
switch_to_light_theme: 'Passer au thème clair',
switch_to_system_theme: 'Passer au thème système',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TranslationLanguage } from './types';
export const ja: TranslationLanguage = {
locale: 'ja',
powered_by_gitbook: 'GitBook提供',
sponsored_via_gitbook: 'GitBookスポンサー',
switch_to_dark_theme: 'ダークテーマに切り替え',
switch_to_light_theme: 'ライトテーマに切り替え',
switch_to_system_theme: 'システムのテーマに切り替え',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TranslationLanguage } from './types';
export const nl: TranslationLanguage = {
locale: 'nl',
powered_by_gitbook: 'Powered by GitBook',
sponsored_via_gitbook: 'Gesponsord door GitBook',
switch_to_dark_theme: 'Schakel over naar donkere modus',
switch_to_light_theme: 'Schakel over naar lichte modus',
switch_to_system_theme: 'Schakel over naar systeemmodus',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/no.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TranslationLanguage } from './types';
export const no: TranslationLanguage = {
locale: 'no',
powered_by_gitbook: 'Drevet av GitBook',
sponsored_via_gitbook: 'Sponset av GitBook',
switch_to_dark_theme: 'Bytt til mørkt tema',
switch_to_light_theme: 'Bytt til lyst tema',
switch_to_system_theme: 'Bytt til systemtema',
Expand Down
3 changes: 2 additions & 1 deletion packages/gitbook/src/intl/translations/pt-br.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const pt_br = {
locale: 'pt-br',
powered_by_gitbook: 'Powered by GitBook',
powered_by_gitbook: 'Fornecido por GitBook',
sponsored_via_gitbook: 'Patrocinado por GitBook',
switch_to_dark_theme: 'Mudar para modo escuro',
switch_to_light_theme: 'Mudar para modo claro',
switch_to_system_theme: 'Mudar para configuração do sistema',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TranslationLanguage } from './types';
export const zh: TranslationLanguage = {
locale: 'zh',
powered_by_gitbook: '由 GitBook 提供支持',
sponsored_via_gitbook: '通过 GitBook 赞助',
switch_to_dark_theme: '切换到深色主题',
switch_to_light_theme: '切换到浅色主题',
switch_to_system_theme: '切换到系统主题',
Expand Down

0 comments on commit bfbed1a

Please sign in to comment.