Skip to content

Commit 848ea65

Browse files
authored
fix(ui): show localized locale name for publish specific locale button (#14906)
Use `getTranslation` for translating localized locale names. Previously, we were using the current **locale** to get the locale label i18n entry. This is incorrect - we need to use the current i18n language, which is what `getTranslation` does. Fixes #14875
1 parent 127e41a commit 848ea65

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

packages/ui/src/elements/PublishButton/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type { PublishButtonClientProps } from 'payload'
44

55
import { useModal } from '@faceless-ui/modal'
6+
import { getTranslation } from '@payloadcms/translations'
67
import { hasAutosaveEnabled, hasScheduledPublishEnabled } from 'payload/shared'
78
import * as qs from 'qs-esm'
89
import React, { useCallback, useEffect, useState } from 'react'
@@ -49,7 +50,7 @@ export function PublishButton({ label: labelProp }: PublishButtonClientProps) {
4950
serverURL,
5051
} = config
5152

52-
const { t } = useTranslation()
53+
const { i18n, t } = useTranslation()
5354
const label = labelProp || t('version:publishChanges')
5455

5556
const entityConfig = React.useMemo(() => {
@@ -197,11 +198,7 @@ export function PublishButton({ label: labelProp }: PublishButtonClientProps) {
197198
typeof locale === 'string' ? locale === localeCode : locale.code === localeCode,
198199
)
199200

200-
const activeLocaleLabel =
201-
activeLocale &&
202-
(typeof activeLocale.label === 'string'
203-
? activeLocale.label
204-
: (activeLocale.label?.[localeCode] ?? undefined))
201+
const activeLocaleLabel = activeLocale && getTranslation(activeLocale.label, i18n)
205202

206203
if (!hasPublishPermission) {
207204
return null

test/localization/config.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,27 +443,47 @@ export default buildConfigWithDefaults({
443443
},
444444
{
445445
code: defaultLocale,
446-
label: 'English',
446+
label: {
447+
de: 'Englisch',
448+
en: 'English',
449+
es: 'Inglés',
450+
},
447451
rtl: false,
448452
},
449453
{
450454
code: spanishLocale,
451-
label: 'Spanish',
455+
label: {
456+
de: 'Spanisch',
457+
en: 'Spanish',
458+
es: 'Español',
459+
},
452460
rtl: false,
453461
},
454462
{
455463
code: portugueseLocale,
456464
fallbackLocale: spanishLocale,
457-
label: 'Portuguese',
465+
label: {
466+
de: 'Portugiesisch',
467+
en: 'Portuguese',
468+
es: 'Portugués',
469+
},
458470
},
459471
{
460472
code: 'ar',
461-
label: 'Arabic',
473+
label: {
474+
de: 'Arabisch',
475+
en: 'Arabic',
476+
es: 'Árabe',
477+
},
462478
rtl: true,
463479
},
464480
{
465481
code: hungarianLocale,
466-
label: 'Hungarian',
482+
label: {
483+
de: 'Ungarische',
484+
en: 'Hungarian',
485+
es: 'Húngaro',
486+
},
467487
rtl: false,
468488
},
469489
],

0 commit comments

Comments
 (0)