Skip to content

Commit 0d8601d

Browse files
heiskrCopilot
andauthored
Add dismissible machine translation banner on non-English pages (#60137)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b888128 commit 0d8601d

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ header:
99
' is currently available as a <a href="/admin/overview/about-upgrades-to-new-releases">release candidate</a>.'
1010
early_access: 📣 Please <b>do not share</b> this URL publicly. This page contains content about a private preview feature.
1111
release_notes_use_latest: Please use the latest release for the latest security, performance, and bug fixes.
12+
machine_translation: Some of this page may have been machine-translated or translated using AI.
1213
# GHES release notes
1314
ghes_release_notes_upgrade_patch_only: 📣 This is not the <a href="#{{ latestPatch }}">latest patch release</a> of Enterprise Server.
1415
ghes_release_notes_upgrade_release_only: 📣 This is not the <a href="/enterprise-server@{{ latestRelease }}/admin/release-notes">latest release</a> of Enterprise Server.

src/fixtures/fixtures/data/ui.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ header:
99
' is currently available as a <a href="/admin/overview/about-upgrades-to-new-releases">release candidate</a>.'
1010
early_access: 📣 Please <b>do not share</b> this URL publicly. This page contains content about a private preview feature.
1111
release_notes_use_latest: Please use the latest release for the latest security, performance, and bug fixes.
12+
machine_translation: Some of this page may have been machine-translated or translated using AI.
1213
# GHES release notes
1314
ghes_release_notes_upgrade_patch_only: 📣 This is not the <a href="#{{ latestPatch }}">latest patch release</a> of Enterprise Server.
1415
ghes_release_notes_upgrade_release_only: 📣 This is not the <a href="/enterprise-server@{{ latestRelease }}/admin/release-notes">latest release</a> of Enterprise Server.

src/frame/components/page-header/HeaderNotifications.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect, useState } from 'react'
22
import { useRouter } from 'next/router'
33
import cx from 'classnames'
44
import { XIcon } from '@primer/octicons-react'
@@ -11,11 +11,14 @@ import { useVersion } from '@/versions/components/useVersion'
1111
import { useUserLanguage } from '@/languages/components/useUserLanguage'
1212
import styles from './HeaderNotifications.module.scss'
1313
import { useSharedUIContext } from '@/frame/components/context/SharedUIContext'
14+
import Cookies from '@/frame/components/lib/cookies'
15+
import { MACHINE_TRANSLATION_BANNER_COOKIE_NAME } from '@/frame/lib/constants'
1416

1517
enum NotificationType {
1618
RELEASE = 'RELEASE',
1719
TRANSLATION = 'TRANSLATION',
1820
EARLY_ACCESS = 'EARLY_ACCESS',
21+
MACHINE_TRANSLATION = 'MACHINE_TRANSLATION',
1922
}
2023

2124
type Notif = {
@@ -36,6 +39,11 @@ export const HeaderNotifications = () => {
3639

3740
const { t } = useTranslation('header')
3841

42+
const [machineTranslationDismissed, setMachineTranslationDismissed] = useState(true)
43+
useEffect(() => {
44+
setMachineTranslationDismissed(Cookies.get(MACHINE_TRANSLATION_BANNER_COOKIE_NAME) === 'true')
45+
}, [])
46+
3947
const translationNotices: Array<Notif> = []
4048
if (router.locale === 'en') {
4149
if (userLanguage && userLanguage !== 'en' && languages[userLanguage]) {
@@ -61,6 +69,22 @@ export const HeaderNotifications = () => {
6169
})
6270
}
6371
}
72+
73+
if (router.locale !== 'en' && !machineTranslationDismissed) {
74+
translationNotices.push({
75+
type: NotificationType.MACHINE_TRANSLATION,
76+
content: t('notices.machine_translation'),
77+
onClose: () => {
78+
setMachineTranslationDismissed(true)
79+
try {
80+
Cookies.set(MACHINE_TRANSLATION_BANNER_COOKIE_NAME, 'true')
81+
} catch (err) {
82+
console.warn('Unable to set cookie', err)
83+
}
84+
},
85+
})
86+
}
87+
6488
const releaseNotices: Array<Notif> = []
6589
if (currentVersion === data.variables.release_candidate.version) {
6690
releaseNotices.push({
@@ -100,6 +124,7 @@ export const HeaderNotifications = () => {
100124
styles.container,
101125
'text-center f5 color-fg-default py-4 px-6 z-1',
102126
type === NotificationType.TRANSLATION && 'color-bg-accent',
127+
type === NotificationType.MACHINE_TRANSLATION && 'color-bg-accent',
103128
type === NotificationType.RELEASE && 'color-bg-accent',
104129
type === NotificationType.EARLY_ACCESS && 'color-bg-danger',
105130
!isLast && 'border-bottom color-border-default',

src/frame/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const DEFAULT_MAX_REQUEST_TIMEOUT = isDev ? 15_000 : 10_000
1212

1313
export const ROOT = process.env.ROOT || '.'
1414
export const USER_LANGUAGE_COOKIE_NAME = 'user_language'
15+
export const MACHINE_TRANSLATION_BANNER_COOKIE_NAME = 'machine_translation_banner_seen'
1516
export const USER_VERSION_COOKIE_NAME = 'user_version'
1617
export const TRANSLATIONS_ROOT = process.env.TRANSLATIONS_ROOT || 'translations'
1718
export const MAX_REQUEST_TIMEOUT = process.env.REQUEST_TIMEOUT

0 commit comments

Comments
 (0)