Fix gettext detection and locale building (#9772)