Implement better text domain merging support

This PR addresses the quite inefficient merging support I implemented with my last PR. It now also ensures that only compatible text domains are merged.