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:
Unit tests
Batch applications
Web server
Command-line interface
Initializing internationalization for a command-line interface application is straightforward:
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:
Define an application state variable.
interface AppState { i18nInitialized: boolean; // Define additional state variables here. }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. }Override the
componentDidMount()
method to initialize internationalization and to force refresh once thePromise
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); }); }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. <></>; }