title: How to convert IETF BCP 47 language identifier to ISO-639-2?
body: <p>I am writing a server API for an iOS application. As a part of the initialization process, the app should send the phone interface language to server via an API call.</p>
  
  <p>The problem is that Apple uses something called <a href="http://tools.ietf.org/html/bcp47" rel="nofollow">IETF BCP 47 language identifier</a> in its <a href="https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSLocale_Class/Reference/Reference.html#jumpTo_18" rel="nofollow"><code>NSLocale preferredLanguages</code> function</a>. </p>
  
  <p>The returned values have different lengths (e.g. <code>[aa, ab, ace, ach, ada, ady, ae, af, afa, afh, agq, ...]</code>, and I found very few parsers that can convert this code to a proper language identifier.</p>
  
  <p>I would like to use the more common <a href="http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes" rel="nofollow">ISO-639-2 three-letters language identifier</a>, which is ubiquitous, has many parsers in many languages, and has a standard, 3-letter representation of languages.</p>
  
  <p><strong>How can I convert a IETF BCP 47 language identifier to ISO-639-2 three-letters language identifier, preferably in Python?</strong></p>