Zend Framework has a great component called Zend_Locale. There's all kind of nitty gritty details in properly parsing out language and locale, partly because it's been hacked into HTTP Accept-Language header.
In the Zend Framework locale docs, it says:
Note: Be aware that there exist not only locales with 2 characters as most people think. Also there are languages and regions which are not only abbreviated with 2 characters. Therefor you should NOT strip the region and language yourself, but use Zend_Locale when you want to strip language or region from a locale string. Otherwise you could have unexpected behaviour within your code when you do this yourself.
Perfect. Except I've been testing out various language translations. Assuming you browse with Firefox, change your settings and add some language_region profiles...change the default order. You'll see that Zend only pulls the default. The docs even say so:
If a user provides more than one locale within his browser, Zend_Locale will use the first found locale. If the user does not provide a locale or the script is being called from the command line the automatic locale 'environment' will automatically be used and returned.
This is unfortunate. If you have 5 languages defined, you want to go through all the locales the user defined in the browser and use a language that matches...
So my question is, what approach would you take to parse the full list and pull out any matches?
UPDATE There's a Zend_Locale::getBrowser() method which returns the full list. Great! Not sure why Zend_Translate only seems to pull the first one then. I'll come back after checking how that works... will probably need to build the array of langs you have translations for and compare it to the results of getBrowser() and pull the first match.
UPDATE2 I did implement a solution, but it's still kind of hacky, because Zend_Translate and Zend_Locale are not small little classes. Internationalization is a large topic, obviously. There's a fair bit to research.
But in essence it boils down to checking each language for matches against the browser preference list.