Skip to content

Add async function for get #1619

@JakobDev

Description

@JakobDev

Current behavior

TranslateService has the method get which returns an Observable of the translation.
If you want to use this in a async function, you need to wrap it into firstValueFrom. e.g.

await firstValueFrom(this.translateService.get("key"));

Expected behavior

There should be an async function that does the same as get but which returns a Promise instead of an Observable. e.g.

await this.translateService.getAsync("key");

What is the motivation / use case for changing the behavior?

I use a async a lot, so I need the firstValueFrom wrapper in a lot of places. If I create a custom function (see below) I would need to use _ every time to mark the translation.

How do you think that we should implement this?

public async getAsync(key: string | string[], interpolateParams?: InterpolationParameters): Promise<Translation> {
  return firstValueFrom(this.get(key, interpolateParams));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions