Extracted the first re-usable chunk from the API translator.

The API translator needs some love to make it easier to understand and
maintain.