Those are handled, usually, by checking the network code reported by SIM and applying a specific package (usually on separate partition) to the system when doing factory reset. The selection of the packages or course varies, and back with smaller flash sizes it was common to have let's say only T-mobile but for multiple countries.