You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our app has a language selector (simple dropdown with the supported languages). Now, to make sure our components look fine in different languages and locales I would like to add this language selector to the sandboxes.
What I have tried is appending it to the template of the main playground component:
@Component({selector: 'language-selector',template: `<button *ngFor="let lang of availableLanguages" (click)="language = lang">{{ lang }}</button>`styleUrls: ['./language-selector.component.scss']})exportclassLanguageSelectorComponent{publicavailableLanguage: any=AVAILABLE_LANGUAGES;constructor(@Inject(DYNAMIC_LANGUAGE_ID)publicreadonlylanguage$: BehaviorSubject<string>){}publicgetlanguage(): string{returnthis.language$.value;}publicsetlanguage(language: string){this.language$.next(language);}}
As you can see the injection token DYNAMIC_LANGUAGE_ID is used to communicate language changes globally.
It displays fine but changing the language does not have any effect on the translations or localized values such as numbers or dates. This seems to be related to impure pipes (which we use for dynamically localizing numbers and date). This can also be replicated with the async pipe when I built a sandbox for this component:
Our app has a language selector (simple dropdown with the supported languages). Now, to make sure our components look fine in different languages and locales I would like to add this language selector to the sandboxes.
What I have tried is appending it to the template of the main playground component:
The language selector roughly looks like this:
As you can see the injection token
DYNAMIC_LANGUAGE_ID
is used to communicate language changes globally.It displays fine but changing the language does not have any effect on the translations or localized values such as numbers or dates. This seems to be related to impure pipes (which we use for dynamically localizing numbers and date). This can also be replicated with the
async
pipe when I built a sandbox for this component:However, when I add the language selector inside the sandboxed component it works fine, eg.
tl;dr:
I'll gladly provide more info or an example project if it helps. Just let me know what you need!
The text was updated successfully, but these errors were encountered: