If you lived on a border of a country that speaks different languages how is it chosen what language you speak? If you lived on the border do you just learn both languages?

Or is it more if you lived even like 500 meters of a border do you learn the language of the country your in? Do people choose it based on nearest popular city to where they’re at?