Closed rubenkuipers closed 3 years ago
You should be able to make a wrapper around <Text>
that accomplishes this by looking up the text with useText
and then manually falling back:
import { useText, Text } from 'preact-i18n';
function ModifiedFallbackText({ children, ...props }) {
const { text } = useText({ text: <Text {...props} /> });
return typeof text === 'undefined' ? children : text;
}
@pl12133 Allright thanks, that could be a solution indeed. Thanks for now :)
Would it be possible to only render the fallback when the translation key value is
undefined
ornull
?In my usecase sometimes a user wants to set an empty string to hide the text. So the key would be defined but empty..
Or is there another way for me to hook into the fallback functionality to customize this behaviour?