Zigzag Phase Transition in Quantum Wires and Localization in the Inhomogeneous One-Dimensional Electron Gas