Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
import i18n from 'i18next'
/**
* Lazy "<Field> is required" message for Zod v4 schemas. Wrap in `{ error: ... }`
* so the message is resolved per validation (not at module load) — keeps the
* literal out of the schema and lets locale changes pick up.
*
* ```ts
* z.string().min(1, { error: requiredMessage('name') })
* z.string().min(1, { error: requiredMessage('payment_method.type') })
* ```
*
* `field` is a dot-path under `admin.fields.*` resolving to a `.label` key —
* `'name'` → `admin.fields.name.label`, `'payment_method.type'` →
* `admin.fields.payment_method.type.label`.
*/
export function requiredMessage(field: string): () => string {
return () => i18n.t('admin.validation.required', { field: i18n.t(`admin.fields.${field}.label`) })
}
/**
* Lazy "<Field> can have at most <count> decimal places" message, for amounts
* and rates the server keeps to a fixed number of decimals.
*/
export function decimalPlacesMessage(field: string, count: number): () => string {
return () =>
i18n.t('admin.validation.too_many_decimals', {
field: i18n.t(`admin.fields.${field}.label`),
count,
})
}