Electric polarization in inhomogeneous crystals