Skip to main content

Use custom translations (i18n)

Ory Elements supports internationalization (i18n) to help you create applications that can be used by users from different locales. This guide will show you how to use custom translations in your Ory Elements components.

Ory Elements uses the react-intl library to handle translations. You can provide your own translations for the Ory Elements components by wrapping your application in the IntlProvider component from react-intl and passing your translations as messages.

Set the default locale

By default, a set of translations is provided for the following locales:

  • English (en)
  • German (de)
  • Spanish (es)
  • French (fr)
  • Italian (it)
  • Swedish (sv)
note

A full list is available in the GitHub repository of Ory Elements. Contributions of new translations are welcome!

To set the default locale for your application, see the locale configuration section.

Detecting a User's Locale

If your application supports multiple languages, you can detect the user's locale and set it dynamically. This can be done using the Accept-Language header from the request in a server-side application or by using the browser's navigator.language property in a client-side application.

Using Custom Translations

To use custom translations in your Ory Elements components, follow these steps:

  1. Install the react-intl library if you haven't already:

    npm install react-intl
  2. Create a translations file (e.g., translations.ts) that contains your translations for different locales. Here is an example:

    translations.ts
    export const messages: Record<string> = {
    en: {
    "login.title": "Login",
    // other messages...
    },
    de: {
    "login.title": "Anmeldung",
    },
    }
    note

    The keys in the messages object should match the keys used in the Ory Elements components. You can find the full original files in the GitHub repository of Ory Elements.

  3. Wrap your application in the IntlProvider component and pass your translations as messages. Here is an example of how to do this in a Next.js application:

    layout.tsx
    import { PropsWithChildren } from "react"
    import { IntlProvider } from "react-intl"
    import { messages } from "./translations"

    export default function Layout({ children }: PropsWithChildren) {
    return (
    <IntlProvider locale="en" messages={messages.en}>
    {children}
    </IntlProvider>
    )
    }