Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Utility Functions

translate()

The translate() function allows you to translate a single key without needing to inject the TranslocoService each time.

import { translate } from '@jsverse/transloco';

translate('hello');

Important This function is a proxy to the TranslocoService.translate method. It will not work if the service hasn't been initialized. Ensure that the translation files are successfully loaded before calling this method.


translateObject()

The translateObject() function allows you to translate an entire object, similarly to the translate() function, without needing to inject the service.

import { translateObject } from '@jsverse/transloco';

translateObject('some.object');

Important This function is a proxy to the TranslocoService.translateObject method. It will not work if the service hasn't been initialized. Ensure that the translation files are successfully loaded before calling this method.


provideGlobalTranslateFn()

provideGlobalTranslateFn() enables the standalone translate() and translateObject() functions above. It is required as of v9 — before then, the functions were wired up automatically.

Both functions resolve against a single Transloco instance, which is what makes them convenient — and what makes them wrong in some setups.

Upgrading from v8? ng update adds this provider for you wherever it finds the functions imported. See the migration guide.


getBrowserLang()

The getBrowserLang() function returns the language code (e.g., "en") detected from the user's browser settings.


getBrowserCultureLang()

The getBrowserCultureLang() function returns the culture language code (e.g., "en-US") detected from the user's browser settings.

Last updated

Was this helpful?