Add salt to eggplants and let them rest for 30 minutes. After that, rinse the eggplants and dry them with kitchen paper. This process will eliminate some of its bitterness.
Pour olive oil into a large pan, stir-fry the eggplants until browned, and set aside. Stir-fry onion and celery for a few minutes, then add tomatoes and stir-fry for a few more minutes.
Add the eggplants, olives, vinegar, capers, and sugar to the pan. Cook for 10 more minutes.
Let the vegetables cool before mixing with the pasta. Caponata is a dish that can be served cold or warm.