שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init doc"v9.4.024.8.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
intlayer Elysia Plugin Documentation
The intlayer plugin for Elysia detects the user's locale and injects an intlayer object into the route context. It also enables the use of the standalone translation functions within the request context.
Usage
העתקת הקוד ללוח
The plugin registers its context through a globalderive, which Elysia types asPartial<{ intlayer: IntlayerContext }>. The value is always present at runtime for routes registered after.use(intlayer()), so use the non-null assertion (intlayer!.t), or optional chaining, to satisfy TypeScript instrictmode.
The same helpers are available as standalone exports, so you can call them without destructuring the route context:
העתקת הקוד ללוח
Description
The plugin performs the following tasks:
- Locale Detection: It reads the locale explicitly set by the client from storage (cookie, header), then falls back to the locale negotiated from the
Accept-Languageheader. If no supported locale matches, it falls back to the configureddefaultLocale. - Context Injection: It adds an
intlayerproperty to the Elysia route context (see the table below). - Dictionary Preparation: It calls
prepareIntlayerwhen the plugin is created, so the dictionaries are built when the app boots.
Route Context
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| Property | Type | Description |
|---|---|---|
locale | Locale | The locale to use for this request. locale_storage takes precedence over locale_detected. |
locale_storage | Locale (optional) | The locale explicitly requested by the client through a cookie or a header. |
locale_detected | Locale | The locale negotiated from the request headers. |
defaultLocale | Locale | The locale configured as fallback in intlayer.config.ts. |
t | TranslateFunction | Translates an inline locale map. |
getIntlayer | typeof getIntlayer | Reads a dictionary by key, defaulting to the request locale. |
getDictionary | typeof getDictionary | Reads an imported dictionary, defaulting to the request locale. |
When called outside of a request handled by the plugin, the standalone helpers fall back to the configured default locale.
Locale Resolution Order
By default, the plugin resolves the locale in this order:
- The
INTLAYER_LOCALEcookie. - The
x-intlayer-localeheader. - The
Accept-Languageheader negotiation. - The configured
defaultLocale.
העתקת הקוד ללוח
Configuration
The plugin reads your intlayer.config.ts file. You can customize the cookie and header used for locale detection:
העתקת הקוד ללוח
import { Locales, type IntlayerConfig } from "intlayer";
const config: IntlayerConfig = {
internationalization: {
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
defaultLocale: Locales.ENGLISH,
},
routing: {
storage: [
{ type: "header", name: "my-locale-header" },
{ type: "cookie", name: "my-locale-cookie" },
],
},
};
export default config;
For more information on configuration, visit the configuration documentation.
