Inserting country codes before CID on incoming

I have several ATA-like devices sending me calls from several countries. Is there any simple way I can insert the international dialling code and country code on these depending on the DID?

i.e. strip “0” and insert “+country code” unless it’s Italy (where if memory serves the “0” is still needed after the country code).
The ATA-like devices don’t all have the capability and I realize that if it’s an overseas (to the DID) number calling in there will be two country codes (so perhaps if it’s by script, I can skip the insertion).