`zsh` has built-in support for that. Use `%2~` instead of `%2/`. See also `%40<...<%~`
See also the `autonamedirs` option:
$ l=/usr/local
$ PS1='%~$ '
~$ setopt autonamedirs
~$ cd /usr/local
~l$
(without `autonamedirs`, you can still do `cd ~l` to `cd` to `/usr/local` and your prompt to show `~l`).