@palamedes/transform
v0.1.1
Published
OXC-based macro transformer for Lingui - transforms Lingui macros to runtime calls without Babel
Maintainers
Readme
@palamedes/transform
OXC-based macro transformer for Lingui. Transforms Lingui macros (e.g., t`Hello`, <Trans>, plural, select) into runtime calls without requiring Babel.
Features
- 🚀 Fast: Uses oxc-parser for high-performance parsing
- 🔧 No Babel required: Works as a standalone transform
- 📦 Framework agnostic: Can be integrated with any bundler via adapters
Installation
pnpm add @palamedes/transformUsage
import { transformLinguiMacros } from "@palamedes/transform"
const result = transformLinguiMacros(sourceCode, "filename.tsx", {
runtimeModule: "@palamedes/runtime",
})
console.log(result.code)API
transformLinguiMacros(code, filename, options?)
Transforms source code containing Lingui macros into runtime calls.
Parameters
code(string): The source code to transformfilename(string): The filename (used for source maps and determining file type)options(object, optional):runtimeModule(string): The module to importgetI18nfrom. Default:"@palamedes/runtime"
Returns
{ code: string, hasChanged: boolean, map: SourceMap | null }: The transformed code, whether any transformations were made, and the generated source map
Supported Macros
t`...`- Tagged template literalt({ id, message })- Call expression with message descriptorplural(count, { one: "...", other: "..." })select(value, { ... })selectOrdinal(count, { ... })<Trans>...</Trans><Plural>,<Select>,<SelectOrdinal>
License
MIT
