Properties of H II region populations in galaxies. II. The H II region luminosity function