Languages

Knit's default UI is in English. To show it in your site's language, pass a locale and your own translations.

Translate the UI

messages overrides any text in the default UI, grouped by area (common, postList, comments, errors, errorCodes and so on). Keys you leave out keep the English defaults, so you can translate gradually.

i18n-messages.tsx
"use client";

import { type KnitMessagesOverride, KnitProvider } from "@knit/react";
import type { ReactNode } from "react";

// Keys you leave out keep the English defaults
const messagesJa: KnitMessagesOverride = {
  common: { login: "ログイン" },
  postList: { newPost: "+ 新しい投稿" },
  errors: {
    rateLimited: (seconds) =>
      seconds ? `${seconds} 秒ほど待ってから試してください。` : "少し待ってから試してください。",
  },
  errorCodes: { NG_WORD_DETECTED: "使えない言葉が含まれています。" },
};

export function KnitShellJa({ children }: { children: ReactNode }) {
  return (
    <KnitProvider
      publishableKey={process.env.NEXT_PUBLIC_KNIT_PUBLISHABLE_KEY ?? ""}
      apiUrl={process.env.NEXT_PUBLIC_KNIT_API_URL ?? ""}
      // Dates, and the language of the sign-in popup
      locale="ja-JP"
      messages={messagesJa}
    >
      {children}
    </KnitProvider>
  );
}

Knit ships English only. Translations are yours to keep, which lets you match the tone of your site.

Dates and the sign-in popup

locale is a BCP 47 tag such as ja-JP. Knit formats dates with it, and the sign-in popup and its one-time-code email use the same language.

The popup is a page on Knit's domain, so it picks its language in this order:

  1. The locale you passed to KnitProvider.
  2. The reader's browser language (Accept-Language).
  3. English.

The popup is available in English and Japanese.

Error messages

Knit's API returns errors as a code and a developer-facing message in English. The message is for logs; readers see text chosen from the code:

  • Codes with their own text are listed in Error codes. Override them with messages.errorCodes.
  • Other errors (input validation, setup mistakes) fall back to a generic message for the action, such as "Failed to save post." Override those with messages.errors.

Hooks and the default UI already return translated text, so show their error values as they are. Don't show err.message from a caught error to readers.