Skip to content

Configuration

ngx-translate is configured using standalone provider functions. The legacy TranslateModule.forRoot/forChild API was removed in v18; see NgModules Support for the transition stub.

For Angular version compatibility, see Angular Compatibility.

Both provider functions accept the same plugin slots (loader, compiler, parser, missingTranslationHandler); the root variant adds language fields (fallbackLang, lang). The plugin slots accept the TranslateProvider shape: a regular Angular Provider object, the matching provideTranslate* helper, a bare class, or a bare factory function. Bare classes and factories are auto-wrapped under the correct DI token (see Bare-class auto-wrap warning).

Configures the root TranslateService at app bootstrap. Use it once in appConfig (or in bootstrapApplication providers).

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

All properties are optional. Plugin slots fall back to no-op / default implementations when omitted.

NameTypeDescription
fallbackLangstringFallback language used when a translation is missing in the current language.
langstringInitial active language on startup.
loaderTranslateProviderProvides a TranslateLoader. Defaults to a no-op loader; provide setTranslation()-loaded data if you don’t use one.
compilerTranslateProviderProvides a TranslateCompiler that pre-processes translations after loading. Defaults to a no-op.
parserTranslateProviderProvides a TranslateParser that interpolates {{ placeholder }} values. Defaults to the bundled TranslateDefaultParser.
missingTranslationHandlerTranslateProviderProvides a MissingTranslationHandler. Defaults to returning the key.

If fallbackLang is unset and a key is missing in the current language, the missingTranslationHandler is invoked directly.

Creates a connected child service with its own store and (optionally) its own loader. Child services delegate currentLang / fallbackLang to the root and walk up the parent chain when a key isn’t found locally. Use this inside route or component providers, typically for lazy-loaded features.

For an isolated child (no parent fallback, own language state), use provideTranslateService() again on the route instead.

feature.routes.ts
import { Routes } from '@angular/router';
import { provideChildTranslateService } from '@ngx-translate/core';
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
export const routes: Routes = [
{
path: 'feature',
providers: [
provideChildTranslateService({
loader: provideTranslateHttpLoader({ prefix: '/assets/i18n/feature/' }),
}),
],
loadChildren: () => import('./feature/feature.routes'),
},
];
NameTypeDescription
loaderTranslateProviderOverride the loader for this child only.
compilerTranslateProviderOverride the compiler for this child only.
parserTranslateProviderOverride the parser for this child only.
missingTranslationHandlerTranslateProviderOverride the handler for this child only.

Unspecified slots use the parent service’s plugins. Most child services only override loader to point at a feature-specific translation file. See Concepts → Hierarchical Services for the chain semantics.

Each plugin ships with a provideTranslate* helper. The helpers accept either a class or a factory function:

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

Use the class form when Angular’s constructor DI can satisfy every dependency of your plugin.

app.config.ts
provideTranslateService({
loader: provideTranslateLoader(MyTranslateLoader),
compiler: provideTranslateCompiler(MyCompiler),
parser: provideTranslateParser(MyParser),
missingTranslationHandler: provideMissingTranslationHandler(MyHandler),
})

Use the factory form when your plugin needs runtime arguments (e.g. a custom path) or values that come from inject(). New in v18.

provideTranslateService({
loader: provideTranslateLoader(() => new MyLoader(inject(HttpClient), '/i18n')),
compiler: provideTranslateCompiler(() => new MyCompiler({ icu: true })),
})

The factory runs inside Angular’s injection context, so you can call inject() freely.

The HTTP loader fetches JSON translation files. v18 adds built-in multi-resource support. Pass a resources array to load and deep-merge several sources per language.

app.config.ts
import { provideTranslateHttpLoader } from '@ngx-translate/http-loader';
provideTranslateService({
loader: provideTranslateHttpLoader({
prefix: '/assets/i18n/',
suffix: '.json',
enforceLoading: false,
useHttpBackend: false,
}),
})
NameTypeDefaultDescription
prefixstring/assets/i18n/URL prefix. Final URL = ${prefix}${lang}${suffix}.
suffixstring.jsonURL suffix.
enforceLoadingbooleanfalseIf true, appends a cache-busting ?enforceLoading=<timestamp> query string to bypass HTTP caches.
useHttpBackendbooleanfalseIf true, bypasses HTTP interceptors by using HttpBackend directly.
failOnErrorbooleanfalseSee failOnError below.

Pass resources instead of prefix/suffix to load and deep-merge several sources per language. Each entry can be a bare prefix string, or a { prefix, suffix } object. All resources are fetched in parallel; results are deep-merged in order, so later entries overwrite earlier entries on key collisions.

provideTranslateHttpLoader({
resources: [
'/assets/i18n/common/', // shared dictionary
{ prefix: '/assets/i18n/feature/', suffix: '.json' }, // feature overrides
],
})
NameTypeDefaultDescription
resources(string | { prefix: string; suffix?: string })[]requiredResources to load and merge per language. Later entries overwrite earlier on collision.
enforceLoadingbooleanfalseCache-busting query string, as above.
useHttpBackendbooleanfalseBypass interceptors via HttpBackend.
failOnErrorbooleanfalseSee failOnError below.

provideTranslateMultiHttpLoader() is also exported as an explicit alias of the multi-resource form.

This built-in support replaces the standalone @codeandweb/ngx-translate-multi-http-loader package.

By default the HTTP loader is permissive (failOnError: false): a failed request (for example a 404 on a missing language file) is caught per-resource, replaced with an empty object, and logged via console.warn(@ngx-translate/http-loader: error loading translation for <lang>: ...). Other resources still contribute their keys, and the app keeps rendering with partial translations.

Pass failOnError: true to restore the v17 fail-fast behavior. Any per-resource failure then propagates and fails the whole language load. Use this when a missing translation file should fail a deploy rather than silently serve a partial dictionary.

provideTranslateHttpLoader({
prefix: '/assets/i18n/',
failOnError: true,
})
Imprint Privacy