Skip to content

Configuration

ngx-translate is configured using provider functions in Angular applications with standalone components.

For detailed information about Angular version compatibility, see the Angular Compatibility documentation.

For comprehensive information about using ngx-translate with NgModules, see the NgModules Support documentation.

Use the provideTranslateService() function in your appConfig to configure the service.

This root TranslateService manages the translations and language changes. You can attach children using the provideChildTranslateService() in components that there the same settings.

You can also provide multiple independent instances of TranslateService using provideTranslateService(). With this, it’s possible to use different languages in parts of your application.

app.config.ts
import { provideTranslateService } from '@ngx-translate/core';
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
export const appConfig: ApplicationConfig = {
providers: [
provideTranslateService({
loader: provideTranslateHttpLoader({prefix:"/i18n/app/"}),
fallbackLang: 'en',
lang: 'de'
})
],
};

All properties are optional.

NameTypeDescription
fallbackLangstringThe fallback language used when a translation is missing in the current language.
langstringThe initial language to set on startup.
extendbooleanDefault: false. When loading additional translations, merges the translations with the already loaded instread of replacing them.
loaderProviderProvides a TranslateLoader to load translations. If not using a loader, you can provide translations useing the setTranslation() method.
compilerProviderProvides a TranslateCompiler to prepare translations after loading.
parserProviderProvides a TranslateParser that interpolates parameters in translations.
missingTranslationHandlerProviderProvides a MissingTranslationHandler that handles missing translations.

If fallbackLang is set, ngx-translate uses that language in case no translation is found in the current language. If it’s not set, the missingTranslationHandler is called.

NameTypeDescription
useDefaultLangbooleanDeprecated: Use fallbackLang instead. If true, shows text from the fallback language if a translation ID is not found.
defaultLanguagestringDeprecated: Use fallbackLang instead. The fallback language used when a translation is missing in the current language.

Use this function in child injectors or lazy-loaded components when using standalone components. This child service is directly connected with the parent TranslateService. Language changes to any of the services are reflected in all services.

The parent and all children share the same translations. By default, loading new translations in a component adds the new translations to the parent TranslateService.

feature.routes.ts
import { provideChildTranslateService } from '@ngx-translate/core';
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
export const routes: Routes = [
{
path: 'feature',
providers: [
provideChildTranslateService({
loader: provideTranslateHttpLoader({prefix:"/i18n/feature/"}),
})
],
loadChildren: () => import('./feature/feature.routes')
}
];

Configuration interface for provideChildTranslateService(). All properties are optional.

NameTypeDescription
extendbooleanDefault: true. When loading translations, merge the translations with the parent TranslateService instead of replacing them.
loaderProviderProvides a TranslateLoader to load translations.
compilerProviderProvides a TranslateCompiler to prepare translations after loading.
parserProviderProvides a TranslateParser that interpolates parameters in translations.
missingTranslationHandlerProviderProvides a MissingTranslationHandler that handles missing translations.

If loader, compiler, parser or missingTranslationHandler is not provided, TranslateService uses the ones provided in the parent TranslateService.

NGX-Translate v17 uses a modern provider function pattern that replaces the traditional Angular provider syntax. For a conceptual overview, see the Provider Functions section in Concepts.

Traditional Angular provider syntax:

{ provide: TranslateLoader, useClass: CustomLoader }

NGX-Translate provider function syntax:

provideTranslateLoader(CustomLoader)

This pattern applies to all provider functions in ngx-translate:

import {
provideTranslateLoader,
provideTranslateCompiler,
provideTranslateParser,
provideMissingTranslationHandler
} from '@ngx-translate/core';

Provider functions should always be used within the provideTranslateService configuration object:

// CORRECT USAGE
provideTranslateService({
loader: provideTranslateLoader(CustomLoader),
compiler: provideTranslateCompiler(CustomCompiler)
})
// INCORRECT USAGE - might not work as expected
[
provideTranslateService(),
provideTranslateLoader(CustomLoader),
provideTranslateCompiler(CustomCompiler)
]

This is because provideTranslateService loads default implementations for any providers not explicitly included in its configuration object. If you provide these services separately, they won’t be used by the TranslateService.

Provides a custom loader implementation.

app.config.ts
import { provideTranslateLoader } from '@ngx-translate/core';
export const appConfig: ApplicationConfig = {
providers: [
provideTranslateService({
loader: provideTranslateLoader(MyTranslateLoader)
})
],
};

Provides a custom compiler implementation.

provideTranslateService({
compiler: provideTranslateCompiler(MyCompiler)
})

Provides a custom parser implementation.

provideTranslateService({
parser: provideTranslateParser(MyParser)
})

Provides a custom missing translation handler implementation.

provideTranslateService({
missingTranslationHandler: provideMissingTranslationHandler(MyHandler)
})

The HTTP loader now uses a configuration-based approach:

app.config.ts
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
export const appConfig: ApplicationConfig = {
providers: [
provideTranslateService({
loader: provideTranslateHttpLoader({
prefix: '/assets/i18n/',
suffix: '.json',
enforceLoading: false,
useHttpBackend: false
})
})
],
};
NameTypeDefaultDescription
prefixstring/assets/i18n/The prefix for translation file URLs.
suffixstring.jsonThe suffix for translation file URLs.
enforceLoadingbooleanfalseIf true, adds a cache-busting timestamp to requests. This ensures that the translations are always fetched from the server instead of using a version from the cache
useHttpBackendbooleanfalseIf true, bypasses HTTP interceptors by using HttpBackend directly.
Imprint Privacy