Package APIs

@i18n-micro/node

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

Node.js utilities for loading translations and locale data in Nuxt I18n Micro.

import { … } from '@i18n-micro/node'

Functions

createI18n

function createI18n(options: I18nOptions): I18n

See I18nOptions · I18n

loadRootTranslations

Load only root-level translations from a directory

function loadRootTranslations(
  dir: string,
  disablePageLocales?: boolean,
): Promise<Record<string, Translations>>
dir
string required
Directory path containing translation files
disablePageLocales
boolean
If true, ignores pages/ folder and treats all files as root translations

See Translations

loadTranslations

Load translations from a directory Supports both flat structure (locales/{lang}.json) and nested structure (locales/pages/{page}/{lang}.json)

function loadTranslations(
  dir: string,
  disablePageLocales?: boolean,
): Promise<LoadedTranslations>
dir
string required
Directory path containing translation files
disablePageLocales
boolean
If true, ignores pages/ folder and treats all files as global translations

Returns — Object with global and route-specific translations

See LoadedTranslations

Classes

I18n

class I18n extends RuntimeI18n {
  constructor(options: I18nOptions)
}
translationDir
string
protected store
ReactiveI18nStore
Inside run, the shared instance answers with the request's locale and route. A fork always answers with its own.
run
<T>(locale: string, fn: (i18n: this) => T) => T
Runs fn with a fork for locale as the current request: until fn and everything it awaits finish, this instance reads and sets that fork's locale and route. fn also gets the fork.
loadTranslations
(dir?: string) => Promise<void>
reload
() => Promise<void>
Re-reads the directory. The old dictionaries answer until the new ones are in, so no request sees an empty instance.

See I18nOptions

Types

I18nOptions

interface I18nOptions extends RuntimeI18nOptions
translationDir
string
disablePageLocales
boolean

LoadedTranslations

interface LoadedTranslations extends TranslationFileBuckets<Translations>

See TranslationFileBuckets · Translations

Re-exports

Declared in another package of this repository and documented on its page.


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