to take the trouble to do something―go to the trouble of doing something―be at the trouble of doing something―go out of one's way to do something―put oneself out of one's way to do something
Thank you kindly for taking the trouble to come all this way
I am greatly obliged to you for your trouble in coming all this way.
Since you have been at the trouble of coming all this way, I will make an exception in your favour.
It is all very well to learn the language of the country, but you need not go to the trouble and expense of engaging a teacher for the purpose.