The description of collective motions in terms of many-body perturbation theory III. The extension of the theory to the non-uniform gas