Skip to content

Add check for presence of a translation #1128

@hoeni

Description

@hoeni

Current behavior

There is no way to be certain about the existence of a translation for a specific key. The best thing I can do is checking if the translation is the same as the given key:
if (this.translate.instant(myKey) === myKey) { ... }
However, besides not being pretty, this cannot detect the case when the translation really is the same as the key.

Expected behavior

It would be nice to have a safe and concise test for the presence of a translation.

How do you think that we should implement this?

if(this.translate.hasTranslation(key)) { ... }

Nice bonus: Give it an optional argument for testing another language instead of the current:
hasTranslation(translationKey: string, language?: string): boolean

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions