Package APIs

@i18n-micro/types-generator

Exported API of @i18n-micro/types-generator, generated from the source.

Type generator for i18n-micro translation keys

Entry points: @i18n-micro/types-generator, @i18n-micro/types-generator/nuxt.

@i18n-micro/types-generator

Components

I18nTypesPlugin

A Vite (and Rollup) plugin: generates at build start, and again in dev after a locale file changes.

function I18nTypesPlugin(options: GeneratorOptions): Plugin

See GeneratorOptions

Functions

formatKeyProperty

Emit a TS property name from a translation key. JSON.stringify covers quotes/newlines/null bytes; U+2028/U+2029 need an extra escape so the .d.ts stays safe when embedded in older JS tooling.

function formatKeyProperty(key: string): string

generateTypes

Generates TypeScript types for translation keys from JSON files. Writes the result to a file.

function generateTypes(options: GeneratorOptions): string
options
GeneratorOptions required
Generator options

Returns — Path to the generated file

See GeneratorOptions

getTypesString

Generates a string with TypeScript types for translation keys. Does not write a file, only returns content.

function getTypesString(options: GeneratorOptions): string
options
GeneratorOptions required
Generator options

Returns — String with .d.ts file content

See GeneratorOptions

Types

GeneratorOptions

interface GeneratorOptions
srcDir
string required
translationDir
string | string[] required
One folder or several (layers, additional dirs); each is resolved against srcDir.
additionalDirs
string[]
Folders of which only the top-level {locale}.json count, as additionalTranslationDirs of the module.
outputFile
string

@i18n-micro/types-generator/nuxt

Functions

default

function default(
  resolvedOptions: I18nTypesGeneratorOptions,
  nuxt: Nuxt,
): ModuleSetupReturn

See I18nTypesGeneratorOptions

Types

I18nTypesGeneratorOptions

interface I18nTypesGeneratorOptions
translationDir
string
Translation directory relative to the project root. Defaults to where nuxt-i18n-micro reads translations.

Generated from the TypeScript sources and their JSDoc by pnpm run docs:generate. Back to all packages · Integration guides