codeTranslation API

A list of the TranslocoService API methods and their usages

circle-check

translate()

Translate a given key, allowing optional parameters for dynamic values or language specification. Use this method when you need to translate keys directly in components or services.

app.component.ts
export class AppComponent {
  constructor(private translocoService: TranslocoService) {}

  ngOnInit() {
    this.translocoService.translate('hello');
    this.translocoService.translate('hello', { value: 'world' });
    this.translocoService.translate(['hello', 'key']);
    this.translocoService.translate('hello', params, 'es');

    // Translate a key from a specific scope
    this.translocoService.translate('hello', params, 'todos/en');
  }
}
circle-exclamation

selectTranslate()

Returns an observable that emits translations. It loads the required translation file automatically.

  • Automatically updates when the active language changes.

  • Supports scoped translations via TRANSLOCO_SCOPE.


translateObject()

Retrieve a nested object or an array of translated values based on keys.

circle-exclamation

selectTranslateObject()

Similar to translateObject(), but returns an observable. It ensures the translation file is loaded.


getTranslation()

Retrieve the entire translation map for the active language or a specific language/scope.


selectTranslation()

Returns an observable that emits the full translation map for the specified language or scope.


setTranslation()

Manually sets translation data for a language or scope. Use merge: true to append data.


setTranslationKey()

Set or update the value of a specific translation key.


events$

Listen to translation events, such as language changes or load failures.

circle-exclamation

Last updated

Was this helpful?