Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update Solid useIntlayer API usage to direct property access"v8.9.004/05/2026
- "Initial history"v8.0.030/12/2025
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Translate your AdonisJS backend website using Intlayer | Internationalisation (i18n)
adonis-intlayer is a powerful internationalisation (i18n) package for AdonisJS applications, designed to make your backend services globally accessible by providing localised responses based on the client's preferences.
Practical Use Cases
Displaying Backend Errors in User's Language: When an error occurs, displaying messages in the user's native language improves understanding and reduces frustration. This is especially useful for dynamic error messages that might be shown in front-end components like toasts or modals.
Retrieving Multilingual Content: For applications pulling content from a database, internationalisation ensures that you can serve this content in multiple languages. This is crucial for platforms like e-commerce sites or content management systems that need to display product descriptions, articles, and other content in the language preferred by the user.
Sending Multilingual Emails: Whether it's transactional emails, marketing campaigns, or notifications, sending emails in the recipient’s language can significantly increase engagement and effectiveness.
Multilingual Push Notifications: For mobile applications, sending push notifications in a user's preferred language can enhance interaction and retention. This personal touch can make notifications feel more relevant and actionable.
Other Communications: Any form of communication from the backend, such as SMS messages, system alerts, or user interface updates, benefits from being in the user's language, ensuring clarity and enhancing the overall user experience.
By internationalising the backend, your application not only respects cultural differences but also aligns better with global market needs, making it a key step in scaling your services worldwide.
Getting Started
See Application Template on GitHub.
Installation
To begin using adonis-intlayer, install the package using npm:
Copy the code to the clipboard
npm install intlayer adonis-intlayernpx intlayer initSetup
Configure the internationalisation settings by creating an intlayer.config.ts in your project root:
Copy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer";
const config: IntlayerConfig = {
internationalization: {
locales: [
Locales.ENGLISH,
Locales.RUSSIAN,
Locales.JAPANESE,
Locales.FRENCH,
Locales.KOREAN,
Locales.CHINESE,
Locales.SPANISH,
Locales.GERMAN,
Locales.ARABIC,
Locales.ITALIAN,
Locales.ENGLISH_UNITED_KINGDOM,
Locales.PORTUGUESE,
Locales.HINDI,
Locales.TURKISH,
Locales.POLISH,
Locales.INDONESIAN,
Locales.VIETNAMESE,
Locales.UKRAINIAN,
],
defaultLocale: Locales.ENGLISH,
},
};
export default config;Declare Your Content
Create and manage your content declarations to store translations:
Copy the code to the clipboard
import { t, type Dictionary } from "intlayer";
const indexContent = {
key: "index",
content: {
exampleOfContent: t({
en: "Example of returned content in English",
"en-GB": "Example of returned content in English (UK)",
fr: "Exemple de contenu renvoyé en français",
"es-ES": "Ejemplo de contenido devuelto en español (España)",
"es-MX": "Ejemplo de contenido devuelto en español (México)",
}),
},
} satisfies Dictionary;
export default indexContent;Your content declarations can be defined anywhere in your application as soon as they are included into thecontentDirdirectory (by default,./srcor./app). And match the content declaration file extension (by default,.content.{json,ts,tsx,js,jsx,mjs,cjs}).
For more details, refer to the content declaration documentation.
AdonisJS Application Setup
Setup your AdonisJS application to use adonis-intlayer.
Register the middleware
First, you need to register the intlayer middleware in your application.
Copy the code to the clipboard
router.use([() => import("adonis-intlayer/middleware")]);Define your routes
Copy the code to the clipboard
import router from "@adonisjs/core/services/router";import { t, getIntlayer, getDictionary } from "adonis-intlayer";import indexContent from "../app/index.content";router.get("/t_example", async () => { return t({ en: "Example of returned content in English", "en-GB": "Example of returned content in English (UK)", fr: "Exemple de contenu renvoyé en français", "es-ES": "Ejemplo de contenido devuelto en español (España)", "es-MX": "Ejemplo de contenido devuelto en español (México)", });});router.get("/getIntlayer_example", async () => { return getIntlayer("index").exampleOfContent;});router.get("/getDictionary_example", async () => { return getDictionary(indexContent).exampleOfContent;});Functions
adonis-intlayer exports several functions to handle internationalisation in your application:
t(content, locale?): Basic translation function.getIntlayer(key, locale?): Retrieve content by key from your dictionaries.getDictionary(dictionary, locale?): Retrieve content from a specific dictionary object.getLocale(): Retrieve the current locale from the request context.
Use in Controllers
Copy the code to the clipboard
import type { HttpContext } from "@adonisjs/core/http";import { t } from "adonis-intlayer";export default class ExampleController { async index({ response }: HttpContext) { return response.send( t({ en: "Hello from controller", "en-GB": "Hello from controller (UK)", fr: "Bonjour depuis le contrôleur", }) ); }}Compatibility
adonis-intlayer is fully compatible with:
react-intlayerfor React applicationsnext-intlayerfor Next.js applicationsvite-intlayerfor Vite applications
It also works seamlessly with any internationalisation solution across various environments, including browsers and API requests. You can customise the middleware to detect locale through headers or cookies:
Copy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer";const config: IntlayerConfig = { // ... Other configuration options middleware: { headerName: "my-locale-header", cookieName: "my-locale-cookie", },};export default config;By default, adonis-intlayer will interpret the Accept-Language header to determine the client's preferred language.
For more information on configuration and advanced topics, visit our documentation.
Configure TypeScript
adonis-intlayer leverages the robust capabilities of TypeScript to enhance the internationalisation process. TypeScript's static typing ensures that every translation key is accounted for, reducing the risk of missing translations and improving maintainability.


Ensure the autogenerated types (by default at ./types/intlayer.d.ts) are included in your tsconfig.json file.
Copy the code to the clipboard
{ // ... Your existing TypeScript configurations "include": [ // ... Your existing TypeScript configurations ".intlayer/**/*.ts", // Include the auto-generated types ],}VS Code Extension
To improve your development experience with Intlayer, you can install the official Intlayer VS Code Extension.
Install from the VS Code Marketplace
This extension provides:
- Autocompletion for translation keys.
- Real-time error detection for missing translations.
- Inline previews of translated content.
- Quick actions to easily create and update translations.
For more details on how to use the extension, refer to the Intlayer VS Code Extension documentation.
Git Configuration
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
To do this, you can add the following instructions to your .gitignore file:
Copy the code to the clipboard
# Ignore the files generated by Intlayer.intlayer