src/app/config/httpLoaderFactory.ts and provides functions to set up ngx-translate with HTTP-based translation file loading.
Functions
provideTranslation()
Configures the ngx-translate loader to load translation files from the file system.The injection token for the translate loader.
Factory function that creates the TranslateHttpLoader instance using
httpLoaderFactory.Dependencies required by the factory function. The HttpClient is injected to make HTTP requests.
httpLoaderFactory()
Creates aTranslateHttpLoader instance with the specified path and file extension.
The Angular HttpClient instance used to load translation files.
TranslateHttpLoader configured to load files from ./assets/i18n/ with .json extension.
File path pattern: ./assets/i18n/{lang}.json
Examples:
- English:
./assets/i18n/en.json - Spanish:
./assets/i18n/es.json
initializeTranslation()
Initializes the translation service with available languages and loads the default or saved language from localStorage.- Injects the
TranslateServiceandLanguageSwitchService - Returns a function that:
- Adds available languages (
['en', 'es']) to the translate service - Sets the default language (
'en') - Initializes the language from localStorage if previously saved
- Adds available languages (
Translation file structure
Translation files are stored insrc/assets/i18n/ with the following structure:
Available languages
The application supports the following languages (defined inLanguageSwitchService):
- English (
en) - Default language - Spanish (
es)
- Update
LanguageSwitchService.availableLanguagesinsrc/app/core/language-switch/language-switch.service.ts:
- Create the corresponding translation file in
src/assets/i18n/(e.g.,fr.json)
Usage in components
To use translations in your components:Related
- Application configuration - How this configuration is integrated
- LanguageSwitchService - Service managing language switching