The Kosterlitz-Thouless-Berezinskii transition of homogeneous and trapped Bose gases in two dimensions