Backend and emails
このコンテンツはまだ日本語訳がありません。
A server handles many users at once, so there is no global language. Pass the recipient’s language explicitly:
const mail = createUseLang(user.locale, translations)((all) => all.mails.welcome)
await sendMail({ to: user.email, subject: mail.subject, text: mail.greeting({ name: user.name }),})Translated Zod errors per request
Section titled “Translated Zod errors per request”For translated Zod errors on the server, let current read the language of the current request, for example from AsyncLocalStorage set in a tRPC or Hono middleware:
import { AsyncLocalStorage } from 'node:async_hooks'
const requestLocale = new AsyncLocalStorage<'en' | 'de'>()
createLang({ base: 'en', languages: ['en', 'de'], current: () => requestLocale.getStore() ?? 'en',})The schema module stays the same in app and backend, see Zod.