So, I am writing a translation wrapper for the react translation hook to replace some text on the app. I have a translationWrapper function that returns a customTFunc as shown below:
export const translationWrapper = (translationName: 'FormValidations' | 'Notifications' | 'Configuration') => {
const { t } = useTranslation(translationName);
const customTFunc = (translationText: Normalize<typeof FormValidations>) => {
const translatedText = t(translationText);
if (someCondition) {
return translatedText.replace("oldText", 'newText');
}
return translatedText;
};
return { customTFunc };
};
Usage:
const { customTFunc } = translationWrapper('FormValidations');
const translatedText = customTFunc('form_validation_translation')
For the customTFunc I want to have its argument translationText dynamically typed based on what was passed to the translationWrapper.
So, if the translationName is "Notifications"; I want the translationText to be Normalize<typeof Notifications>