From f447e5b78505aa83f80c4f6a7f088e7d2c553418 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Mon, 6 Jan 2025 16:29:34 -0600 Subject: [PATCH 1/2] use translation --- apps/site/components/withMetaBar.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/site/components/withMetaBar.tsx b/apps/site/components/withMetaBar.tsx index 612052305c51c..c56c7bbe68b67 100644 --- a/apps/site/components/withMetaBar.tsx +++ b/apps/site/components/withMetaBar.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useFormatter } from 'next-intl'; +import { useFormatter, useTranslations } from 'next-intl'; import type { FC } from 'react'; import MetaBar from '@/components/Containers/MetaBar'; @@ -22,6 +22,8 @@ const WithMetaBar: FC = () => { const usernames = frontmatter.authors?.split(',').map(author => author.trim()) ?? []; + const t = useTranslations(); + // Since we cannot show the same number of avatars in Mobile / Tablet // resolution as we do on desktop and there is overflow, we are adjusting // the number of avatars manually for the resolutions below @@ -47,7 +49,9 @@ const WithMetaBar: FC = () => { 'components.metabar.contribute': ( <> - Edit this page + + {t('components.metabar.contributeText')} + ), }} From 503ae1301630ee890dcdefca1fe71d708d1b3479 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Mon, 6 Jan 2025 17:13:02 -0600 Subject: [PATCH 2/2] feat: translate "Edit this page", linking appropriately based on locale --- apps/site/components/withMetaBar.tsx | 13 +++++++++++-- apps/site/next.constants.mjs | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/site/components/withMetaBar.tsx b/apps/site/components/withMetaBar.tsx index c56c7bbe68b67..b06fd40704a47 100644 --- a/apps/site/components/withMetaBar.tsx +++ b/apps/site/components/withMetaBar.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useFormatter, useTranslations } from 'next-intl'; +import { useFormatter, useLocale, useTranslations } from 'next-intl'; import type { FC } from 'react'; import MetaBar from '@/components/Containers/MetaBar'; @@ -10,6 +10,8 @@ import WithAvatarGroup from '@/components/withAvatarGroup'; import { useClientContext } from '@/hooks/react-client'; import useMediaQuery from '@/hooks/react-client/useMediaQuery'; import { DEFAULT_DATE_FORMAT } from '@/next.calendar.constants.mjs'; +import { TRANSLATION_URL } from '@/next.constants.mjs'; +import { defaultLocale } from '@/next.locales.mjs'; import { getGitHubBlobUrl } from '@/util/gitHubUtils'; const WithMetaBar: FC = () => { @@ -23,6 +25,7 @@ const WithMetaBar: FC = () => { frontmatter.authors?.split(',').map(author => author.trim()) ?? []; const t = useTranslations(); + const locale = useLocale(); // Since we cannot show the same number of avatars in Mobile / Tablet // resolution as we do on desktop and there is overflow, we are adjusting @@ -49,7 +52,13 @@ const WithMetaBar: FC = () => { 'components.metabar.contribute': ( <> - + {t('components.metabar.contributeText')} diff --git a/apps/site/next.constants.mjs b/apps/site/next.constants.mjs index c1d75c04dd6f0..3df5797431b16 100644 --- a/apps/site/next.constants.mjs +++ b/apps/site/next.constants.mjs @@ -187,3 +187,9 @@ export const ORAMA_CLOUD_API_KEY = * Note: This has no NEXT_PUBLIC prefix as it should not be exposed to the Browser. */ export const GITHUB_API_KEY = process.env.NEXT_GITHUB_API_KEY || ''; + +/** + * The resource we point people to when discussing internationalization efforts. + */ +export const TRANSLATION_URL = + 'https://github.com/nodejs/nodejs.org/blob/main/TRANSLATION.md#how-to-translate';