Yes, asking first should be your default, especially for close-up portraits. Beyond politeness, some countries have privacy laws where publishing someone's identifiable image without consent can cause legal trouble, and in many cultures photographing women, children or elderly people without permission is a serious offence to the family.
The request itself does not need perfect language. Make eye contact, smile, hold up your camera or phone slightly, and say the local word for photo with a questioning tone, or simply ask in English. Most people will either nod, wave you off, or pose happily. Learning the words for please and thank you in the local language makes the whole interaction warmer.
If someone declines, accept it gracefully and move on without arguing. And a lovely touch that costs nothing: show them the photo afterwards. In some tourist-heavy spots people may ask for a small tip for posing, which is their livelihood, so decide beforehand whether you are comfortable with that.