Skip to content

I18nPlugin

This file defines the I18nPlugin class, which implements the internationalization (i18n) plugin for the @sodacore/core framework. The plugin loads its metadata from package.json and registers all necessary i18n services and providers with the application.


Features

  • Automatic Metadata Loading: Reads plugin metadata (name, version, description, author) from package.json at runtime.
  • Service Registration: Registers the i18n provider and service with the application during installation.
  • Extends BasePlugin: Inherits from BasePlugin for consistent plugin lifecycle and configuration handling.

Usage

typescript
import I18nPlugin from './module/plugin';
import Application from '@sodacore/core';

const app = new Application();
const i18nPlugin = new I18nPlugin();
await i18nPlugin.install(app);

API

Properties

  • name: The plugin name, loaded from package.json.
  • version: The plugin version, loaded from package.json.
  • description: The plugin description, loaded from package.json.
  • author: The plugin author, loaded from package.json.

Constructor

typescript
constructor(protected config: IConfig = {})
  • config: Optional configuration object for the plugin.

Methods

async install(app: Application): Promise<void>

Registers the i18n provider and service with the Sodacore application instance:

  • I18nProvider
  • I18nService

How It Works

  1. Loads plugin metadata from package.json using Bun's file API.
  2. Sets the plugin's metadata properties.
  3. On installation, registers the i18n provider and service with the Sodacore application.

Notes

  • This plugin is designed to be used with the Sodacore framework and expects Bun as the runtime.
  • Throws an error if package.json is not found.
  • All i18n-related functionality is encapsulated and registered via the install method.

Released under the Apache-2.0 License.