Add context for better translations
Sometimes you need to add some context to get the proper translation. For example, Retour in French could mean Return or Back, depending on the context. Or even Back could mean a back button or my back, who knows ?
- React (web)
- React Native
- Node.js
import { I18nKeylessText } from "i18n-keyless-react";
return (
<I18nKeylessText context="This is a back button">
Retour
</I18nKeylessText>
);
}
import { getTranslation } from "i18n-keyless-react";
return (
<p>
{getTranslation('Retour', { context: "This is a back button" })}
</p>
);
}
import { I18nKeylessText } from "i18n-keyless-react";
return (
<I18nKeylessText context="This is a back button">
Retour
</I18nKeylessText>
);
}
import { getTranslation } from "i18n-keyless-react";
return (
<p>
{getTranslation('Retour', { context: "This is a back button" })}
</p>
);
}
warning
awaitForTranslation NEED to be awaited, to prevent 429 to happen.
import { awaitForTranslation, type Lang } from 'i18n-keyless-node';
async function sendNotificationsToUsers() {
// ...
const title = await awaitForTranslation(
"Viens voir l'application",
user.lang as Lang,
{ context: "This is the title of a notification "}
);
// ...
}