Add check for presence of a translation
See original GitHub issueCurrent 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:26
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Is there a function to check the existence of a translation in ...
I need to check if a translation for the plugin currently exists, otherwise present a fall-back for a limited number of languages. Example:...
Read more >Types of Quality Checks
Check that insertables in the source are correctly transferred to the translation. Insertables are unicode characters such as new line hyphens. The insertable ......
Read more >Checks and fixups
The quality checks help catch common translator errors, ensuring the translation is in good shape. The checks can be ignored in case of...
Read more >Translate and localize your app - Play Console Help
If you add text translations without localized graphic assets, your app's ... To view your app in another language and check your app's...
Read more >Improve Translate
Contributing is a major part of our process to add new languages to Google Translate. If you speak a language that we're working...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Another way to do it:
A slightly improved version of @spixy where you can reference deep keys via dot notation eg.
VERY.DEEP.TRANSLATION