Skip to content

Commit bc0b3a5

Browse files
committed
feat(plugin-nested-docs): support for translations
Introduces translation keys and default translations for the nested docs plugin fields (breadcrumbs, parent). This enables the plugin to display its UI labels in multiple languages within the Payload admin, improving user experience for internationalized installations. The plugin now registers its own translation namespace, allowing its field labels to be localized and overridden through the main Payload i18n configuration.
1 parent 5ca3afb commit bc0b3a5

12 files changed

Lines changed: 144 additions & 2 deletions

File tree

packages/plugin-nested-docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"lint:fix": "eslint . --fix"
4848
},
4949
"devDependencies": {
50+
"@payloadcms/translations": "workspace:*",
5051
"@payloadcms/eslint-config": "workspace:*",
5152
"payload": "workspace:*"
5253
},

packages/plugin-nested-docs/src/fields/breadcrumbs.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export const createBreadcrumbsField = (
66
): Field => ({
77
name: 'breadcrumbs',
88
type: 'array',
9+
labels: {
10+
// @ts-expect-error - translations are not typed in plugins yet
11+
plural: ({ t }) => t('plugin-nested-docs:breadcrumbsPlural'),
12+
// @ts-expect-error - translations are not typed in plugins yet
13+
singular: ({ t }) => t('plugin-nested-docs:breadcrumbsSingular'),
14+
},
915
localized: true,
1016
...(overrides || {}),
1117
admin: {
@@ -19,6 +25,8 @@ export const createBreadcrumbsField = (
1925
admin: {
2026
disabled: true,
2127
},
28+
// @ts-expect-error - translations are not typed in plugins yet
29+
label: ({ t }) => t('plugin-nested-docs:doc'),
2230
maxDepth: 0,
2331
relationTo,
2432
},
@@ -31,14 +39,17 @@ export const createBreadcrumbsField = (
3139
admin: {
3240
width: '50%',
3341
},
34-
label: 'URL',
42+
// @ts-expect-error - translations are not typed in plugins yet
43+
label: ({ t }) => t('plugin-nested-docs:url'),
3544
},
3645
{
3746
name: 'label',
3847
type: 'text',
3948
admin: {
4049
width: '50%',
4150
},
51+
// @ts-expect-error - translations are not typed in plugins yet
52+
label: ({ t }) => t('plugin-nested-docs:label'),
4253
},
4354
],
4455
},

packages/plugin-nested-docs/src/fields/parent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const createParentField = (
1313
position: 'sidebar',
1414
...(overrides?.admin || {}),
1515
},
16+
// @ts-expect-error - translations are not typed in plugins yet
17+
label: ({ t }) => t('plugin-nested-docs:parent'),
1618
// filterOptions are assigned dynamically based on the pluginConfig
1719
// filterOptions: parentFilterOptions(),
1820
type: 'relationship',

packages/plugin-nested-docs/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Plugin, SingleRelationshipField } from 'payload'
22

3+
import { deepMergeSimple } from 'payload/shared'
4+
35
import type { NestedDocsPluginConfig } from './types.js'
46

57
import { createBreadcrumbsField } from './fields/breadcrumbs.js'
@@ -8,7 +10,9 @@ import { parentFilterOptions } from './fields/parentFilterOptions.js'
810
import { populateBreadcrumbsBeforeChange } from './hooks/populateBreadcrumbsBeforeChange.js'
911
import { resaveChildren } from './hooks/resaveChildren.js'
1012
import { resaveSelfAfterCreate } from './hooks/resaveSelfAfterCreate.js'
13+
import { translations } from './translations/index.js'
1114
import { getParents } from './utilities/getParents.js'
15+
export { translations as nestedDocsTranslations } from './translations/index.js'
1216

1317
export { createBreadcrumbsField, createParentField, getParents }
1418

@@ -67,4 +71,8 @@ export const nestedDocsPlugin =
6771

6872
return collection
6973
}),
74+
i18n: {
75+
...config.i18n,
76+
translations: deepMergeSimple(translations, config.i18n?.translations ?? {}),
77+
},
7078
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { GenericTranslationsObject, NestedKeysStripped } from '@payloadcms/translations'
2+
3+
import { de } from './languages/de.js'
4+
import { en } from './languages/en.js'
5+
import { it } from './languages/it.js'
6+
7+
export const translations = {
8+
de,
9+
en,
10+
it,
11+
}
12+
13+
export type PluginNestedDocsTranslations = GenericTranslationsObject
14+
15+
export type PluginNestedDocsTranslationKeys = NestedKeysStripped<PluginNestedDocsTranslations>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { GenericTranslationsObject } from '@payloadcms/translations'
2+
3+
export const de: GenericTranslationsObject = {
4+
$schema: './translation-schema.json',
5+
'plugin-nested-docs': {
6+
breadcrumbsPlural: 'Navigationspfade',
7+
breadcrumbsSingular: 'Navigationspfad',
8+
doc: 'Dokument',
9+
label: 'Bezeichnung',
10+
parent: 'Übergeordnetes Dokument',
11+
url: 'URL',
12+
},
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { GenericTranslationsObject } from '@payloadcms/translations'
2+
3+
export const en: GenericTranslationsObject = {
4+
$schema: './translation-schema.json',
5+
'plugin-nested-docs': {
6+
breadcrumbsPlural: 'Breadcrumbs',
7+
breadcrumbsSingular: 'Breadcrumb',
8+
doc: 'Document',
9+
label: 'Label',
10+
parent: 'Parent Document',
11+
url: 'URL',
12+
},
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { GenericTranslationsObject } from '@payloadcms/translations'
2+
3+
export const it: GenericTranslationsObject = {
4+
$schema: './translation-schema.json',
5+
'plugin-nested-docs': {
6+
breadcrumbsPlural: 'Percorsi di navigazione',
7+
breadcrumbsSingular: 'Percorso di navigazione',
8+
doc: 'Documento',
9+
label: 'Etichetta',
10+
parent: 'Documento genitore',
11+
url: 'URL',
12+
},
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "object",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
4+
"additionalProperties": false,
5+
"properties": {
6+
"$schema": {
7+
"type": "string"
8+
},
9+
"plugin-nested-docs": {
10+
"type": "object",
11+
"additionalProperties": false,
12+
"properties": {
13+
"breadcrumbsPlural": {
14+
"type": "string"
15+
},
16+
"breadcrumbsSingular": {
17+
"type": "string"
18+
},
19+
"doc": {
20+
"type": "string"
21+
},
22+
"label": {
23+
"type": "string"
24+
},
25+
"parent": {
26+
"type": "string"
27+
},
28+
"url": {
29+
"type": "string"
30+
}
31+
},
32+
"required": ["breadcrumbsPlural", "breadcrumbsSingular", "doc", "label", "parent", "url"]
33+
}
34+
},
35+
"required": ["plugin-nested-docs"]
36+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { en } from './languages/en.js'
2+
3+
export type PluginDefaultTranslationsObject = typeof en

0 commit comments

Comments
 (0)