Closed
Description
For some translations, the id
(the key in other words) is the same as the translations (e.g. the Invalid credentials.
in the security domain):
export const INVALID_CREDENTIALS = {"id":"Invalid credentials.","translations":{"security":{"fr":"Identifiants invalides.","en":"Invalid credentials.","de":"Fehlerhafte Zugangsdaten.","it":"Credenziali non valide."}}};
Therefore, there is no way in the frontend to distinguish a missing translation from a translation that have the same id
(key) same as a translation because the only way I found in the frontend to detect if the translation is missing is checking if the result from the trans
method is the same as the id. For example:
const translationConstant = aServiceThat.findConstantById(messageId);
// I'm voluntarily trying in the default domain (`messages`) even though I know the message isn't there.
let translatedMessage = translator.trans(translator[translationConstant]);
if (translatedMessage === translator[translationConstant].id) {
// Here how I distinguish a missing translation from a translation that have a same value as his id when no exception is thrown. If an exception was thrown, I could try something else (e.g. search in another domain)
}
To solve this problem, I think we could pass an additional to the trans
method with a default value (throwWhenNotFound = false
) and catch the exception later.
Metadata
Metadata
Assignees
Labels
No labels