AIDC Toolkit Help

Core Package

The core package provides support for internationalization, built on the robust and popular i18next package. Applications can take advantage of the additional abstraction provided by the core package by adding their own resource bundles or can manage internationalization themselves.

Internationalization

Applications built on the AIDC Toolkit must initialize internationalization first via this package. Support is available for the following environments:

Command-line interface

Initializing internationalization for a command-line interface application is straightforward:

await i18nInit(I18NEnvironment.CLI);

Web browser

Initializing internationalization for a web browser requires awaiting the fulfillment of the Promise returned by the call to i18nInit() before rendering any content. For example, in the React framework, this may be accomplished as follows:

  1. Define an application state variable.

    interface AppState { i18nInitialized: boolean; // Define additional state variables here. }
  2. Define the application class and initialize the state.

    export default class App extends AppComponent<object, AppState> { override state: AppState = { i18nInitialized: false, // Initialize additional state variables here. }; // Remainder of class. }
  3. Override the componentDidMount() method to initialize internationalization and to force refresh once the Promise is fulfilled.

    override componentDidMount(): void { i18nInit(I18NEnvironment.Browser, true).then((initialized) => { if (initialized) { // Force refresh. this.setState(state => ({ ...state, i18nInitialized: initialized })); } }).catch((e: unknown) => { console.error(e); alert(e); }); }
  4. Override the render() method to render the initial content, but only once the application has been initialized.

    override render(): ReactElement { return this.state.i18nInitialized ? // Render the application. <Navbar className="d-flex" expand="lg"> // ... </Navbar> : // Render nothing. <></>; }
Last modified: 28 September 2024