Updated: Aug 13, 2020
First, don't beat yourself up if you do this. Translating in your head is a perfectly fine intermediate step when learning a language.
You will translate things in your head when you haven’t had much experience expressing a certain idea; it’s a pretty natural thing to do.
One thing you can do to not be so dependent on direct translation is to not only learn through translation. You can do this by doing an image search of the word in your target language. You will get to see how native speakers actually use the word as opposed to just knowing its closest equivalent in English. This will also help your brain build new connections and remember the word better.
The other solution to this is pretty obvious: practice. Make sure you have someone who can correct your mistakes and provide good feedback. It could be an instructor or a language exchange partner.
This is another important trick I learned that helps you stop translating: practice speaking faster. If you’re speaking quickly, you won't have time to translate in your head; you will have to express yourself naturally in the language. One thing I do, if I am reading something, I will read it out loud until it flows naturally and comfortably. Gradually, speaking your target language will become an activity that you can do subconsciously, without thinking.
Try these methods out and hopefully, you will experience that great side-effect of not translating things in your head: that feeling of fluency.