Zadaj pytanie i otrzymaj streszczenie dokumentu, odwołując się do tej strony i wybranego dostawcy AI
Dzięki integracji serwera Intlayer MCP z ulubionym asystentem AI możesz uzyskać dostęp do całej dokumentacji bezpośrednio z ChatGPT, DeepSeek, Cursor, VSCode itp.
Zobacz dokumentację serwera MCPTreść tej strony została przetłumaczona przy użyciu sztucznej inteligencji.
Zobacz ostatnią wersję oryginalnej treści w języku angielskimJeśli masz pomysł na ulepszenie tej dokumentacji, zachęcamy do przesłania pull requesta na GitHubie.
Link do dokumentacji na GitHubieKopiuj dokument Markdown do schowka
Declaration of Per-Locale Content Declaration in Intlayer
Intlayer supports two ways to declare multilingual content:
- Single file with all translations
- One file per locale (per-locale format)
This flexibility enables:
- Easy migration from other i18n tools
- Support for automated translation workflows
- Clear organization of translations into separate, locale-specific files
Single File with Multiple Translations
This format is ideal for:
- Quick iteration in code.
- Seamless integration with the CMS.
This is the recommended approach for most use cases. It centralizes translations, making it easy to iterate and integrate with the CMS.
Skopiuj kod do schowka
import { t, type Dictionary } from "intlayer";const helloWorldContent = { key: "hello-world", content: { multilingualContent: t({ en: "Title of my component", es: "Título de mi componente", }), },} satisfies Dictionary;export default helloWorldContent;Recommended: This format is best when using Intlayer's visual editor or managing translations directly in the code.
Per-Locale Format
This format is useful when:
- You want to version or override translations independently.
- You're integrating machine or human translation workflows.
You can also split translations into individual locale files by specifying the locale field:
Skopiuj kod do schowka
import { t, Locales, type Dictionary } from "intlayer";const helloWorldContent = { key: "hello-world", locale: Locales.ENGLISH, // Important content: { multilingualContent: "Title of my component" },} satisfies Dictionary;export default helloWorldContent;Skopiuj kod do schowka
import { t, Locales, type Dictionary } from "intlayer";const helloWorldContent = { key: "hello-world", locale: Locales.SPANISH, // Important content: { multilingualContent: "Título de mi componente" },} satisfies Dictionary;export default helloWorldContent;Important: Make sure the locale field is defined. It tells Intlayer which language the file represents.
Note: In both cases, the content declaration file must follow the naming pattern *.content.{ts,tsx,js,jsx,mjs,cjs,json} to be recognized by Intlayer. The .[locale] suffix is optional and used only as a naming convention.
Mixing Formats
You can combine both declaration approaches for the same content key. For example:
- Declare your base content statically in a file like index.content.ts.
- Add or override specific translations in separate files such as index.fr.content.ts or index.content.json.
This setup is especially useful when:
- You want to define the initial content structure in code.
- You plan to enrich or complete translations later using the CMS or automated tools.
.└── Components └── MyComponent ├── index.content.ts ├── index.content.json └── index.tsExample
Here a multilingual content declaration file:
Skopiuj kod do schowka
import { t, type Dictionary } from "intlayer";const helloWorldContent = { key: "hello-world", locale: Locales.ENGLISH, content: { multilingualContent: "Title of my component", projectName: "My project", },} satisfies Dictionary;export default helloWorldContent;Skopiuj kod do schowka
{ "$schema": "https://intlayer.org/schema.json", "key": "hello-world", "content": { "multilingualContent": { "nodeType": "translation", "translation": { "fr": "Titre de mon composant", "es": "Título de mi componente" } } }}Intlayer merges multilingual and per-locale files automatically.
Skopiuj kod do schowka
import { getIntlayer, Locales } from "intlayer";const intlayer = getIntlayer("hello-world"); // Default locale is ENGLISH, so it will return the ENGLISH contentconsole.log(JSON.stringify(intlayer, null, 2));// Result:// {// "multilingualContent": "Title of my component",// "projectName": "My project"// }const intlayer = getIntlayer("hello-world", Locales.SPANISH);console.log(JSON.stringify(intlayer, null, 2));// Result:// {// "multilingualContent": "Título de mi componente",// "projectName": "My project"// }const intlayer = getIntlayer("hello-world", Locales.FRENCH);console.log(JSON.stringify(intlayer, null, 2));// Result:// {// "multilingualContent": "Titre de mon composant",// "projectName": "My project"// }Automatic Translation Generation
Use the intlayer CLI to auto-fill missing translations based on your preferred services.