Consider using this service with LocalizedRouteAware for faster bootstrapping.
Your bridge to the language services of your user's app is the LanguageIntegrationService
. Inject it into your services and components and your library will be able to get the supported languages, perform translations and more.
enabled
- Vefiying integration presenceThe service is always injectable. However it is up to the app developer using your library to import the language integration module. If the module hasn't been imported, the service is considered to be 'disabled'.
When the service is disabled methods might throw an error and properties might return
null
orundefined
values.
To verify that the app has enabled language integration, use the enabled
property.
ready
- Vefiying integration readinessSome apps might take some time to load their translation files or initialize their language services. To hook into the initialization process and know when the app's language services are ready, use the ready
property.
If the app didn't provide a ready promise or observable, the
ready
property will complete immediately.
The following example verifies that integration has been enabled, then registers handlers for readiness and language changes.
The
LocalizedRouteAware
class provides the above implementation and more out of the box. Consider extending it.
If your library requires the language integration tools and cannot provide a default behaviour without them, you can use the ensureEnabled()
method to throw an explanatory error to the app's developer, telling him he must import the module. If integration has been enabled, the method will exit without an error.
To force integration, the constructor in the above example could be changed as follows:
Providing integration from an app