>>> parse_accept_header('en-us', LanguageAccept).best_match(['en', 'de'])
>>> parse_accept_header('en', LanguageAccept).best_match(['en-us', 'de'])
Both those calls return None. I'm not sure if there's a RFC specifying the behaviour for this but shouldn't a territory-less language always work if there's no exact match available? I.e. if the client specified en-us, en would be fine and more important, if the client specified en and the server just knows en-us that one should be used.
This is important in cases like the following one: There's an application using Flask-Babel which has english as its native language (i.e. hardcoded) because it's nice to keep code in english and a translation, e.g. german. That language is the default language though (because the main audience of the site speaks german). However, if a client sends an Accept-Languages for en (or any en-*) the english "translation" should be used. But without specifying en and all en-* language codes when calling best_match() it will return None (or de depending on the passed arguments) instead - even though the user's header clearly says he prefers english.
Both those calls return
None. I'm not sure if there's a RFC specifying the behaviour for this but shouldn't a territory-less language always work if there's no exact match available? I.e. if the client specifieden-us,enwould be fine and more important, if the client specifiedenand the server just knowsen-usthat one should be used.This is important in cases like the following one: There's an application using Flask-Babel which has english as its native language (i.e. hardcoded) because it's nice to keep code in english and a translation, e.g. german. That language is the default language though (because the main audience of the site speaks german). However, if a client sends an Accept-Languages for
en(or anyen-*) the english "translation" should be used. But without specifyingenand allen-*language codes when callingbest_match()it will returnNone(ordedepending on the passed arguments) instead - even though the user's header clearly says he prefers english.