Skip to main content

i18n - overview

When designing an application, you will often find a need to have a translation layer within your app, where text that is delivered to your user can be carefully translated based on their preferred language. Psychic supports two complementary patterns for this:

  1. Code-driven i18n — translate static values that are the same for every user (enum labels, UI strings) using locale files and a light-weight, typescript-forward i18n function.
  2. Data-driven i18n — translate user-generated content that's unique per record (a place's title, a listing's description) using the polymorphic LocalizedText model.

Both patterns resolve the locale from the same source — typically the Accept-Language request header — and pass it down through passthrough, so a single resolved locale can drive both an enum label and a record's translated title in the same response.

const text = i18n('en-US', 'labels.nutrition.calories')
tip
  • For guides on setting up code-driven i18n, see the config guides.
  • For guides on using code-driven i18n, see the usage guides.
  • For the data-driven LocalizedText pattern, see passthrough.