bun plugin to compile Lingui macro
npm install bun-plugin-lingui-macro> bun plugin to compile Lingui macro
The plugin will add a babel with @lingui/babel-plugin-lingui-macro to your bun setup.
Plugin will process only files where macro import is found.
If you already have babel or SWC in your pipeline consider to use @lingui/babel-plugin-lingui-macro or@lingui/swc-plugin directly.
``sh`
bun add --dev bun-plugin-lingui-macronpm install --save-dev bun-plugin-lingui-macro
yarn add --dev bun-plugin-lingui-macro
`ts
import { pluginLinguiMacro } from "bun-plugin-lingui-macro";
await Bun.build({
plugins: [pluginLinguiMacro()],
});
`
To disable the .po file loader:
`ts`
await Bun.build({
plugins: [pluginLinguiMacro({ loader: false })],
});
The plugin will transform Lingui macros in your .js/.ts files:
`typescript
import { Trans } from "@lingui/macro";
// This will be compiled at build time
`
The plugin also supports direct imports of .po catalog files, eliminating the need for a separate lingui compile step:
`typescript
import { messages as enMessages } from "./locales/en/messages.po";
import { messages as fiMessages } from "./locales/fi/messages.po";
i18n.load({
en: enMessages,
fi: fiMessages,
});
`
The plugin automatically:
1. Loads the .po file using your lingui.config.js configurationexport const messages = {...}
2. Compiles it to JavaScript using Lingui's compiler
3. Returns an ES module:
TypeScript Support:
Create a lingui.d.ts file in your project for proper type checking:
`typescript`
declare module "*.po" {
import type { Messages } from "@lingui/core";
export const messages: Messages;
}
This provides type safety and autocomplete for your .po` imports.
This package is licensed under MIT license.