From 918c5b32df5edccdb4edd6aa83f7963822ab00c2 Mon Sep 17 00:00:00 2001 From: Timofei Iatsenko Date: Fri, 4 Oct 2024 11:54:47 +0200 Subject: [PATCH] add documentation --- website/docs/ref/core.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/website/docs/ref/core.md b/website/docs/ref/core.md index e102fe927..8584a8353 100644 --- a/website/docs/ref/core.md +++ b/website/docs/ref/core.md @@ -115,16 +115,32 @@ Formatting of messages as strings (e.g: `"My name is {name}"`) works in developm The same example would in real application look like this: ```ts -import { i18n } from "@lingui/core" +import { i18n } from "@lingui/core"; // File generated by `lingui compile` -import { messages: messagesEn } from "./locale/en/messages.js" +import { messages as messagesEn } from "./locale/en/messages.js"; -i18n.load('en', messagesEn) +i18n.load("en", messagesEn); ``` ::: +### `i18n.setMessagesCompiler(compiler)` {#i18n.setMessagesCompiler} + +Registers a `MessageCompiler` to enable the use of uncompiled catalogs at runtime. + +In production builds, the `MessageCompiler` is typically excluded to reduce bundle size. + +By default, message catalogs should be precompiled during the build process. However, if you need to compile catalogs at runtime, you can use this method to set a message compiler. + +Example usage: + +```ts +import { compileMessage } from "@lingui/message-utils/compileMessage"; + +i18n.setMessagesCompiler(compileMessage); +``` + ### `i18n.activate(locale[, locales])` {#i18n.activate} Activate a locale and locales. From now on, calling `i18n._` will return messages in given locale.