24 lines
655 B
TypeScript
24 lines
655 B
TypeScript
import type { Config } from 'payload'
|
|
|
|
import type { I18nConfig } from './types.js'
|
|
|
|
type PayloadLocalizationConfig = NonNullable<Config['localization']>
|
|
|
|
/**
|
|
* Transforms validated i18n config into Payload's localization object.
|
|
* Pure function — no side effects, no validation (caller validates first).
|
|
*/
|
|
export function buildLocalizationConfig(config: I18nConfig): PayloadLocalizationConfig {
|
|
const { defaultLocale, fallback = true, locales } = config
|
|
|
|
return {
|
|
defaultLocale,
|
|
fallback,
|
|
locales: locales.map((locale) => ({
|
|
code: locale.code,
|
|
label: locale.label,
|
|
...(locale.rtl && { rtl: true }),
|
|
})),
|
|
}
|
|
}
|