Skip to main content
Version: 5.x.x

Translating

Use tolgee.t method to translate keys.

domElement.textContent = tolgee.t('key', 'Default value');

However this will not update translation in case you change language or update translation through in-context.

Listening for changes

info

If you use Tolgee with any supported framework, this is solved for you automatically.

You can listen for translation change with update event.

tolgee.on('update', () => {
domElement.textContent = tolgee.t('key', 'Default value');
});

This event gets triggered when any translation need to be updated, so it might be inefficient if you use many namespaces. Therefore there is also onNsUpdate method, which allows you to subscribe only to selected namespaces.

tolgee
.onNsUpdate(() => {
domElement.textContent = tolgee.t('key', 'Default value');
})
.subscribeNs('my_namespace');