Skip to content

Instantly share code, notes, and snippets.

@mmikhan
Created October 31, 2025 12:13
Show Gist options
  • Save mmikhan/fd5b949b4bf8030cbe7ea9a7bdada857 to your computer and use it in GitHub Desktop.
Save mmikhan/fd5b949b4bf8030cbe7ea9a7bdada857 to your computer and use it in GitHub Desktop.
Payload Seed multiple locales
import { localization } from '@/i18n/localization'
import type { Category } from '@/payload-types'
import type { RequiredDataFromCollectionSlug, TypedLocale } from 'payload'
type Data = {
title?: string
slug?: string
icon?: string
}
type Props = {
parent?: Category
locales: TypedLocale[]
data: Record<TypedLocale, Data>
}
type CategorySeed = RequiredDataFromCollectionSlug<'categories'> & { locale: TypedLocale }
const seed = ({ parent, locales, data }: Props): CategorySeed[] => {
return locales.map((locale) => ({
title: data[locale]?.title ?? '',
icon: data[locale]?.icon ?? '',
slug: data[locale]?.slug ?? '',
parent,
locale,
}))
}
export const electronicsCategory = seed({
locales: localization.locales.map((l) => l.code) as TypedLocale[],
data: {
en: { title: 'Electronics', slug: 'electronics', icon: 'tv' },
nl: { title: 'Elektronica', slug: 'electronics', icon: 'tv' },
bn: { title: 'ইলেকট্রনিক্স', slug: 'electronics', icon: 'tv' },
},
})
const payloadReq = await createLocalReq({ user }, payload)
await Promise.all(
electronicsCategory.map((category) => {
return payload.create({
collection: 'categories',
data: category,
req: payloadReq,
depth: 0,
locale: category.locale,
})
}),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment