Skip to content

[Bug]: Dynamically load the translations - Angular #795

@DiscJockeyDJ

Description

@DiscJockeyDJ

Expected Behavior

Display the translations when the language is changed through the @ngx-translate service.

Current Behavior

I tried using the setLanguage method, but I believe once run is called, the config won't get updated. Hence, setLanguage isn't working?

Steps to reproduce

Currently, I have like this

ngOnInit(): void {
this.translationService.onLangChange.subscribe((event) => {
// event.translations?.['cookie'] would contain the translations for different languages.
const cookie =(event.translations?.['cookie'] as CookieTranslations) ?? null;
if (cookie) {
CookieConsent.run({
guiOptions: this.guiOptions,
categories: this.categories,
language: {
default: event.language,
translations: {
[event.language] = {
consentModal: {
title: cookie.title,
description: cookie.description,
// and so on
} // The rest of the properties using cookie constant
}
})
}

At this point, how do I ensure that the translations are reflected accordingly when a language is changed?

Proposed fix or additional info.

No response

Version

3.1.0

On which browser do you see the issue?

Chrome, Firefox, Safari, Microsoft Edge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions