Provide a fallback for LanguageAccept under Safari#1507
Conversation
|
It appears this is a known issue? #450 It looks like there might be a better way to do this than what I came up with. I'll do a bit more research when I have time. For the time being my app is using my own function instead of |
|
After some research, I don't see a better way to handle this, but I did add some additional tests. |
|
Have the tests become more strict? Did I miss something? The |
|
You need to follow the style checks, in this case ensure you use Black to format the code. You can see the changes it wants to make here: https://travis-ci.org/pallets/werkzeug/jobs/524209888#L219-L262 You can install pre-commit to have this done automatically before commits. |
d89e73d to
a61e6d6
Compare
|
This doesn't go the opposite direction, where the client accepts a = LanguageAccept((("en", 0.9),))
m = a.best_match(("en_US",))
print(m) # None |
If no exact match is found, first tries modifying the accepted values to use primary tags only, then tries modifying the matched values to use primary tags only. If the client only accepts "en-US", "en" will match. If the client only accepts "en", "en-US" will match. 2 and 3 lettter codes are supported. Fallback matching is not performed with other subtags.
a61e6d6 to
9bfca43
Compare
|
Added a fallback in the other direction. The process is now:
Also fixed to match 3-letter primary tags, like "aus". Given the way the code is written, you could imagine a fourth fallback where the primary tag is considered for both the accept and match values at the same time. This doesn't make sense however, as "en-GB" would then match "en-US". |
Safari on macOS doesn't provide a language-only option in the header for languages accepted. When
en-USis the preferred language, Safari only provides an "Accepted Language" ofen-USwithout any fallback toen. Therefore, if a website is offering anenlanguage version but not anen-USversion,LanguageAccept.best_matchreturnsNone.This pull request attempts to correct that by checking if
Noneis returned and if so, trying again with language-only accepted values.fixes #450