Usage Chart
How strongly this package shapes the runtime
Package Flow
How this package moves through xtaskjs runtime phases
Before startup
Register locales, formatters, fallback settings, and optional locale resolvers so translation rules are known before request handling starts.
During CreateApplication()
Internationalization initializes request-aware locale services before controllers and views are resolved, enabling injected translations and formatting from the first request.
During app.close()
The lifecycle manager releases runtime translation state together with the rest of the application services.
API Surface
Representative exports from the upstream package
Configuration and locales
- configureInternationalization
- Internationalization
- registerInternationalizationLocale
- InternationalizationLocale
- InternationalizationResolver
Translation runtime
- InternationalizationService
- InjectInternationalizationService
- InjectI18nService
- runWithInternationalizationContext
Formatting and lifecycle
- registerInternationalizationFormatter
- InjectInternationalizationLifecycleManager
- InjectI18nLifecycleManager
- initializeInternationalizationIntegration
- shutdownInternationalizationIntegration
Usage
Typical adoption flow
1. Configure locales and fallbacks
Register your locale catalogs, default locale, fallback locale, and any custom formatters during startup.
2. Resolve locale from the request
Use query parameters, Accept-Language, cookies, or custom resolvers to make the current locale part of request context.
3. Inject translations into pages and services
Call the injected service inside controllers, views, presenters, and domain helpers so all formatting stays consistent.
Example
Reference snippet
import { Service } from "@xtaskjs/core";
import {
InjectInternationalizationService,
InternationalizationService,
configureInternationalization,
registerInternationalizationLocale,
} from "@xtaskjs/internationalization";
configureInternationalization({
defaultLocale: "en-US",
fallbackLocale: "en-US",
});
registerInternationalizationLocale({
locale: "en-US",
translations: { checkout: { total: "Total: {{amount, currency}}" } },
});
@Service()
export class CheckoutPresenter {
constructor(
@InjectInternationalizationService()
private readonly intl: InternationalizationService
) {}
presentTotal(amount: number) {
return this.intl.t("checkout.total", { params: { amount } });
}
}
Samples
Official samples to inspect next
Reference samples: 09-internationalization_app and 10-internationalization_express_app
Related
Packages commonly used with this one