Solid.js Integration
Relevant source files
The following files were used as context for generating this wiki page:
The @i18n-micro/solid package provides SolidJS bindings for the i18n-micro ecosystem. It enables reactive translations, context management, and UI components using the same core logic found in the primary Nuxt module.
This integration allows developers to use a framework-agnostic runtime for internationalization within SolidJS applications. It supports features such as pluralization, interpolation, and route-specific logic while maintaining a small bundle size and high performance.
Sources: packages/solid/README.md:1-5, AGENTS.md:12-19
Architecture and Data Flow
The SolidJS integration functions as a wrapper around the @i18n-micro/core and @i18n-micro/runtime packages. It manages the application's internationalization state through a provider-consumer model.
Provider-Based Initialization
You initialize the system by creating an i18n instance and wrapping your application in an I18nProvider. This provider makes the translation state available throughout the component tree.
The diagram shows the initialization flow from configuration to component usage.
Sources: packages/solid/README.md:11-30
Reactive State Management
The integration uses SolidJS primitives to handle reactive updates. When you call setLocale, the system updates the internal state, triggering a re-render of components using translation functions like t or tc.
The sequence diagram illustrates how a locale change propagates through the system to update translations.
Sources: packages/solid/CHANGELOG.md:100-103, packages/solid/README.md:40-52
Key Components and APIs
Core Functions
| Function | Purpose |
|---|---|
createI18n | Initializes the i18n configuration including locales, fallback locales, and messages. |
I18nProvider | Context provider that distributes the i18n instance to child components. |
useI18n | Hook used within components to access translation methods and state. |
Sources: packages/solid/README.md:11-15
Translation Methods
The useI18n hook returns several utilities for handling localized content:
t(key, params): Performs standard translation with optional interpolation.tc(key, count): Handles pluralization based on a provided numeric count.locale: Returns a reactive signal representing the current active locale.setLocale(code): Updates the current active locale across the application.
Sources: packages/solid/README.md:40-52
Configuration and Dependencies
The package requires solid-js as a peer dependency and optionally integrates with @solidjs/router for route-aware translations.
Dependency Table
| Dependency | Type | Version Requirement |
|---|---|---|
@i18n-micro/core | Internal | workspace:^ |
@i18n-micro/types | Internal | workspace:^ |
solid-js | Peer | catalog: (Required) |
@solidjs/router | Peer | catalog: (Optional) |
Sources: packages/solid/package.json:55-75
Implementation Detail: Translation Storage
As of version 1.1.0, the integration uses TranslationStorage instead of a standard cache to manage message data. This change optimizes how translations are stored and retrieved during runtime, aligning with the project's goal of low runtime cost.
Sources: packages/solid/CHANGELOG.md:100-103, AGENTS.md:12-16
Summary
The SolidJS integration offers a lightweight method for implementing internationalization. By utilizing the framework-agnostic @i18n-micro/runtime and @i18n-micro/core, it ensures consistency across different frameworks in the ecosystem. The system provides a familiar SolidJS experience through hooks and providers while maintaining the performance standards of the nuxt-i18n-micro project.