Various part of MediaWiki (such as the installer, or ULS) autodetect the language of a request and match it to the closest MediaWiki / Translatewiki language code, but the capability is not exposed via the API.
There should be a single service that does this, it should be part of MediaWiki core, and it should be available from the API (maybe as part of userinfo), so that tools which use Wikimedia's internationalization system can easily find the best supported language. In a first approximation, the internal logic should probably be something like this:
- if the user is logged in, use the interface language
- allow extensions to provide a language via a hook (ULS would check for the language cookie here)
- parse the Accept-Language header, go through it in decreasing order of priority, and try to match language tags or the first components of language tags to MediaWiki language names.