Services
The Internationalization package exposes IntlService
service for default and customized internationalization of locales and LocalizationService
for providing messages based on the current language.
Using the IntlService
in Components
To use the service in your own components:
- Use the
IntlProvider
component in your parent component. - If you require locale data that is different from the default
en-US
locale data, load the data you need in your parent component. - Access the
IntlService
:- In Functional Components—Through the
useInternationalization
hook. - In Class Components —Register your child component for internationalization by using the
registerForIntl
function and consume it through theprovideIntlService
function.
- In Functional Components—Through the
Applying the LocalizationService
in Components
The toLanguageString
method of the LocalizationService
accepts a key and a default value. To use the LocalizationService
in your own components in conjunction with the LocalizationProvider
:
- Use the
LocalizationProvider
component in your parent component. - Set the
language
property. - Access the
LocalizationService
:- In Functional Components—Through the
useLocalization
hook. - In Class Components —Register your child component for internationalization by using the
registerForLocalization
function and consume it through theprovideLocalizationService
function.
- In Functional Components—Through the
Customizing the Default Service
To override the default behavior of the internationalization service:
- Inherit
IntlService
and override the necessary methods. - Inherit the
IntlProvider
component and override itsgetIntlService
method. - Use the customized
IntlProvider
component.