Skip to content

Accept language #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 26, 2022
Merged

Accept language #109

merged 4 commits into from
Oct 26, 2022

Conversation

ewdurbin
Copy link
Member

superseedes #53

kilrogg and others added 3 commits October 26, 2022 09:32
This adds support for using the Accept-Language header to Fastly config for the currently known locales.
Unfortunately needs to be edited every time locales change.
... to make intentions clearer.
@ewdurbin
Copy link
Member Author

ewdurbin commented Oct 26, 2022

The one outstanding issue I see is that we currently have is that Babel uses CLDR language tags and Accept-Language uses IANA language tags... which use different casing and locale differentiators (_ vs - respectively).

So I think our PyPI-Locale key space will get a bit larger. Thus users relying on Accept-Language (IANA) will have a separate cache from users relying on the _LOCALE_ cookie (CLDR) for some languages (pt_BR vs pt-BR for example). Solutions would be to attempt to transform them or store our own mapping I guess?

@ewdurbin
Copy link
Member Author

@di here is a Fastly Fiddle that shows how things work: https://fiddle.fastly.dev/fiddle/3506e1d7#req-8aa50147

@ewdurbin ewdurbin merged commit da82a18 into main Oct 26, 2022
@ewdurbin ewdurbin deleted the accept-language branch October 26, 2022 17:19
@ewdurbin
Copy link
Member Author

@webknjaz this is now live on https://test.pypi.org for validation. I'm going to be poking at it to make sure all is well for a bit before making live on pypi.org

ewdurbin added a commit to pypi/warehouse that referenced this pull request Oct 26, 2022
With support for Accept-Language header from pypi/infra#109 we need to add a step so our VCL knows about the new locale.
di pushed a commit to pypi/warehouse that referenced this pull request Oct 26, 2022
With support for Accept-Language header from pypi/infra#109 we need to add a step so our VCL knows about the new locale.
@ewdurbin
Copy link
Member Author

Active now for https://pypi.org

@webknjaz
Copy link
Member

webknjaz commented Nov 4, 2022

Sorry, I forgot to report back. This seems to work correctly on the HTTP level, per my testing:

$ curl -ssvH 'Accept-Language: uk,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: uk,en]
> accept-language: uk,en
<html lang="uk" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">

$ curl -ssvH 'Accept-Language: en,uk,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: en,uk,en]
> accept-language: en,uk,en
<html lang="en" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">
    <meta name="description" content="The Python Package Index (PyPI) is a repository of software for the Python programming language.">

$ curl -ssvH 'Accept-Language: weird,en,uk,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: weird,en,uk,en]
> accept-language: weird,en,uk,en
<html lang="en" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">
    <meta name="description" content="The Python Package Index (PyPI) is a repository of software for the Python programming language.">

$ curl -ssvH 'Accept-Language: weird,uk,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang   
* h2h3 [accept-language: weird,uk,en]
> accept-language: weird,uk,en
<html lang="uk" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">

$ curl -ssvH 'Accept-Language: weird,BR,uk-UA,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: weird,BR,uk-UA,en]
> accept-language: weird,BR,uk-UA,en
<html lang="uk" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">

$ curl -ssvH 'Accept-Language: weird,pt-BR,uk-UA,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: weird,pt-BR,uk-UA,en]
> accept-language: weird,pt-BR,uk-UA,en
<html lang="pt_BR" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">

$ curl -ssvH 'Accept-Language: weird,pt,pt-BR,uk-UA,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: weird,pt,pt-BR,uk-UA,en]
> accept-language: weird,pt,pt-BR,uk-UA,en
<html lang="pt_BR" dir="ltr">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">

# rtl test:
$ curl -ssvH 'Accept-Language: weird,he,pt,pt-BR,uk-UA,en' https://pypi.org 2>&1 | head -c 5500 | grep -i lang
* h2h3 [accept-language: weird,he,pt,pt-BR,uk-UA,en]
> accept-language: weird,he,pt,pt-BR,uk-UA,en
<html lang="he" dir="rtl">
    <meta name="defaultLanguage" content="en">
    <meta name="availableLanguages" content="en, es, fr, ja, pt_BR, uk, el, de, zh_Hans, zh_Hant, ru, he, eo">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants