이 페이지와 원하는 AI 어시스턴트를 사용하여 문서를 요약합니다
버전 기록
- "Initial documentation"v9.4.02026. 8. 23.
이 페이지의 콘텐츠는 AI를 사용하여 번역되었습니다.
영어 원본 내용의 최신 버전을 보기이 문서를 개선할 아이디어가 있으시면 GitHub에 풀 리퀘스트를 제출하여 자유롭게 기여해 주세요.
문서에 대한 GitHub 링크문서의 Markdown을 클립보드에 복사
Documentation: getIntlayer Function in intlayer
Description
The getIntlayer function picks one dictionary by its key and returns its content interpreted for a given locale. It is the framework-agnostic counterpart of the useIntlayer hook: same content, same selectors, but usable anywhere a React context is not available — Node scripts, server functions, route loaders, metadata builders, Express/Fastify handlers, tests.
It reads the dictionaries generated by Intlayer in .intlayer/, so the key argument is typed and autocompleted from your own content declarations, and the returned object is fully typed down to each leaf.
Key Features:
- Typed dictionary keys and typed returned content
- Interprets every content node (
t(),enu(),cond(),insert(),nest(),md(),html(),file(),gender()) - Accepts a locale or a selector object (collections, variants)
- Results are memoized per
key + locale + selector - Falls back to a safe proxy in development when a dictionary is missing, instead of crashing
Function Signature
코드를 클립보드에 복사
Parameters
key: DictionaryKeys- Description: The key of the dictionary to read, as declared in your content files.
- Type:
DictionaryKeys— a union of every declared dictionary key. - Required: Yes
localeOrSelector: LocalesValues | DictionarySelector- Description: The locale to interpret the content with, or a selector object for dynamic dictionaries.
'fr'— a locale{ item: 2 }— a collection item (omititemto get every item as an array){ variant: 'black-friday' }— a named variant (omit for thedefaultone){ variant: { id: 'prod_abc', userId: '123' } }— a structured variant- Any selector can carry a locale:
{ item: 2, locale: 'fr' }
- Type:
LocalesValues | DictionarySelector - Required: No (Optional) — defaults to the configured
defaultLocale.
- Description: The locale to interpret the content with, or a selector object for dynamic dictionaries.
plugins: Plugins[]- Description: Custom node transformers replacing the base interpreter plugins. Advanced use only; omit it to keep the default behaviour.
- Type:
Plugins[] - Required: No (Optional)
Returns
- Type: The interpreted content of the dictionary, typed from your declaration.
- Description: A plain object mirroring the
contentfield of your dictionary, where every Intlayer node has been resolved to its final value for the requested locale.
Example Usage
Basic Usage
코드를 클립보드에 복사
코드를 클립보드에 복사
import { getIntlayer } from "intlayer";
const { title } = getIntlayer("app", "fr"); // "Bonjour"
Without a locale
Omitting the locale interprets the content with the defaultLocale declared in your configuration.
코드를 클립보드에 복사
Inside a server handler
코드를 클립보드에 복사
With a selector (collections and variants)
코드를 클립보드에 복사
Behaviour Notes
Caching
Results are memoized in a module-level cache keyed by key + locale + selector. Calling getIntlayer("app", "fr") repeatedly interprets the dictionary once and returns the very same object afterwards.
Missing dictionaries
In development, requesting a key that has no generated dictionary logs a warning once and returns a safe fallback proxy: reading content.title yields the string "app.title" instead of throwing. This keeps a page usable while the missing declaration is fixed. Run the Intlayer build (or the dev server) so the dictionary is generated.
Bundle size
getIntlayer reads the merged dictionary, which holds every locale. In client bundles, the build plugins rewrite the call so only the required content is shipped. When you read content outside of rendering (metadata, loaders, server functions) and want a single locale loaded on demand, use getIntlayerAsync instead.
Related Functions
getIntlayerAsync: Async counterpart loading a single locale chunk.getDictionary: Interprets a dictionary object you pass yourself, instead of one looked up by key.useIntlayer: The React hook equivalent, reading the locale from the provider.
TypeScript
코드를 클립보드에 복사