I work with 2 languages: c# and python.
I use them both in the same project, but obviously for different tasks.
When I'm working on a task, I work on that task until it is in a complete state, or until I can't concentrate on it any more. This means, if I have to switch between languages, there is little to no cognitive dissonance as I'll have already come out of thinking in either language when I'm done with the last task.
Admittedly I will take a short break when I come out of a task, which probably helps a lot.