chore: dynamically loads translations

This commit is contained in:
James
2024-04-08 16:25:21 -04:00
parent 24c348dc49
commit 30948ab545
179 changed files with 997 additions and 12237 deletions

View File

@@ -2,41 +2,28 @@ import type { User } from 'payload/auth'
import type { Config } from 'payload/config'
import type { Field } from 'payload/types'
import { extractTranslations } from 'payload/utilities'
const translations = extractTranslations([
'fields:textToDisplay',
'fields:linkType',
'fields:chooseBetweenCustomTextOrDocument',
'fields:customURL',
'fields:internalLink',
'fields:enterURL',
'fields:chooseDocumentToLink',
'fields:openInNewTab',
])
export const getBaseFields = (config: Config): Field[] => [
{
name: 'text',
type: 'text',
label: translations['fields:textToDisplay'],
label: ({ t }) => t('fields:textToDisplay'),
required: true,
},
{
name: 'linkType',
type: 'radio',
admin: {
description: translations['fields:chooseBetweenCustomTextOrDocument'],
description: ({ t }) => t('fields:chooseBetweenCustomTextOrDocument'),
},
defaultValue: 'custom',
label: translations['fields:linkType'],
label: ({ t }) => t('fields:linkType'),
options: [
{
label: translations['fields:customURL'],
label: ({ t }) => t('fields:customURL'),
value: 'custom',
},
{
label: translations['fields:internalLink'],
label: ({ t }) => t('fields:internalLink'),
value: 'internal',
},
],
@@ -48,7 +35,7 @@ export const getBaseFields = (config: Config): Field[] => [
admin: {
condition: ({ linkType }) => linkType !== 'internal',
},
label: translations['fields:enterURL'],
label: ({ t }) => t('fields:enterURL'),
required: true,
},
{
@@ -66,7 +53,7 @@ export const getBaseFields = (config: Config): Field[] => [
return false
}
},
label: translations['fields:chooseDocumentToLink'],
label: ({ t }) => t('fields:chooseDocumentToLink'),
relationTo: config.collections
.filter(({ admin: { enableRichTextLink, hidden } }) => {
if (typeof hidden !== 'function' && hidden) {
@@ -80,6 +67,6 @@ export const getBaseFields = (config: Config): Field[] => [
{
name: 'newTab',
type: 'checkbox',
label: translations['fields:openInNewTab'],
label: ({ t }) => t('fields:openInNewTab'),
},
]

View File

@@ -1,7 +1,5 @@
import type { RichTextAdapter } from 'payload/types'
import { initI18n } from '@payloadcms/translations'
import { translations } from '@payloadcms/translations/client'
import { mapFields } from '@payloadcms/ui/utilities/buildComponentMap'
import { sanitizeFields } from 'payload/config'
import React from 'react'
@@ -16,10 +14,9 @@ import { defaultLeaves as leafTypes } from './field/leaves/index.js'
export const getGenerateComponentMap =
(args: AdapterArguments): RichTextAdapter['generateComponentMap'] =>
({ config }) => {
({ config, i18n }) => {
const componentMap = new Map()
const i18n = initI18n({ config: config.i18n, context: 'client', translations })
const validRelationships = config.collections.map((c) => c.slug) || []
;(args?.admin?.leaves || Object.values(leafTypes)).forEach((leaf) => {
@@ -78,6 +75,7 @@ export const getGenerateComponentMap =
const mappedFields = mapFields({
config,
fieldSchema: linkFields,
i18n,
readOnly: false,
})
@@ -108,6 +106,7 @@ export const getGenerateComponentMap =
const mappedFields = mapFields({
config,
fieldSchema: uploadFields,
i18n,
readOnly: false,
})

View File

@@ -1,7 +1,6 @@
import type { RichTextAdapter } from 'payload/types'
import { initI18n } from '@payloadcms/translations'
import { translations } from '@payloadcms/translations/client'
import { sanitizeFields } from 'payload/config'
import type { AdapterArguments, RichTextCustomElement } from './types.js'
@@ -13,8 +12,8 @@ import { uploadFieldsSchemaPath } from './field/elements/upload/shared.js'
export const getGenerateSchemaMap =
(args: AdapterArguments): RichTextAdapter['generateSchemaMap'] =>
({ config, schemaMap, schemaPath }) => {
const i18n = initI18n({ config: config.i18n, context: 'client', translations })
async ({ config, schemaMap, schemaPath }) => {
const i18n = await initI18n({ config: config.i18n, context: 'client' })
const validRelationships = config.collections.map((c) => c.slug) || []
;(args?.admin?.elements || Object.values(elementTypes)).forEach((el) => {