So after doing some more research and asking postgres developers it seems that it is not currently possible to get the error code from PQconnectdbParams().
This seems to be a shortcoming of libpq itself which doesn't try to assign SQLState error codes for errors it detects internally (like an unknown hostname).
This seems to be on the postgres dev todo list but it's not a priority.
TL;DR: If you are going to use libpq, learn to live with the text error message (whatever language it is localized in).