Skip to main content

Localization

Here are the key patterns and best practices we follow for implementing localization (l10n) in our application.

Zod Schema Localization

The Problem with Hardcoded Messages

Avoid hardcoding error messages directly in your schemas:

Schema with hardcoded error messages

This approach makes it difficult to support multiple languages and maintain consistent messaging across your application.

Best Practice: Schema Factory Pattern

Instead, use the Schema Factory Pattern. Create a schema factory function that accepts a translation function (t) to make your schemas reusable across different locales:

schema factory function

Implementation Example

Don't create schemas with hardcoded messages:

old Schema pattern

Do use the Schema Factory Pattern:

new Schema pattern