A unified picture of Galactic and cosmological fast radio bursts