Skip to content

bpo-31159: fix language switch regex on unknown yet built languages.#3039

Merged
vstinner merged 1 commit intopython:masterfrom
JulienPalard:doc-fix-switch
Aug 9, 2017
Merged

bpo-31159: fix language switch regex on unknown yet built languages.#3039
vstinner merged 1 commit intopython:masterfrom
JulienPalard:doc-fix-switch

Conversation

@JulienPalard
Copy link
Copy Markdown
Member

@JulienPalard JulienPalard commented Aug 9, 2017

This fix a regex issue (a missing non-matching group around an 'or'
list) and the specific possible case where a translation is built but
not yet in known by the picker, but not explicitly listing possible
languages in the regex.

https://bugs.python.org/issue31159

This fix a regex issue (a missing non-matching group around an 'or'
list) and the specific possible case where a translation is built but
not yet in known by the picker, but not explicitly listing possible
languages in the regex.
// or '' if not found.
function language_segment_from_url(url) {
var language_regexp = '\.org/(' + Object.keys(all_languages).join('|') + '/)';
var language_regexp = '\.org/([a-z]{2}(?:-[a-z]{2})?/)';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep using all_languages and just add (?: xxx ) to the regex.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I would prefer to keep it too, but I though:

var language_regexp = '\.org/((?:' + Object.keys(all_languages).join('|') + '|([a-z]{2}(?:-[a-z]{2})?)/)';

was pretty unreadable/unmaintainable just to match a language tag in an URL.

Sure we can enhance it by building a list of "language tag regexes" based on all_languages and adding the [a-z]{2}(?:-[a-z]{2})? to the end of it, then concatenating them all using the join('|'). Still a bit huge but more maintainable.

In every cases we have to keep the wildcardy part [a-z]{2}(?:-[a-z]{2})? to allow matching still-unknown languages (ones that are built, but not yet in the switcher, which is a supported case, see: https://www.python.org/dev/peps/pep-0545/#add-translation-to-the-language-switcher).

Or... we may add an exhaustive list of languages, not used to build the switcher but used to build the regex, containing every language tag we expect in the future, so when a translation is built, the switcher already knows it.

In any cases I find ([a-z]{2}(?:-[a-z]{2})?/) easier to read and maintain, even if it has a little chance to collide with a version in the future: if we introduce a version like dev but containing only two letters (or four letters separated by a dash). But I don't see this happen.

@vstinner vstinner merged commit 122081d into python:master Aug 9, 2017
@vstinner
Copy link
Copy Markdown
Member

vstinner commented Aug 9, 2017

Ok, it makes sense. I merged your PR.

JulienPalard added a commit to JulienPalard/cpython that referenced this pull request Aug 9, 2017
…ython#3039)

This fix a regex issue (a missing non-matching group around an 'or'
list) and the specific possible case where a translation is built but
not yet in known by the picker, but not explicitly listing possible
languages in the regex.
(cherry picked from commit 122081d)
vstinner pushed a commit that referenced this pull request Aug 10, 2017
#3051)

* bpo-31159: fix language switch regex on unknown yet built languages. (#3039)

This fix a regex issue (a missing non-matching group around an 'or'
list) and the specific possible case where a translation is built but
not yet in known by the picker, but not explicitly listing possible
languages in the regex.
(cherry picked from commit 122081d)

* bpo-31149: Doc: Add Japanese to the language switcher. (#3028)

(cherry picked from commit c82b7f3)
JulienPalard added a commit to JulienPalard/cpython that referenced this pull request Aug 13, 2017
python#3051)

* bpo-31159: fix language switch regex on unknown yet built languages. (python#3039)

This fix a regex issue (a missing non-matching group around an 'or'
list) and the specific possible case where a translation is built but
not yet in known by the picker, but not explicitly listing possible
languages in the regex.
(cherry picked from commit 122081d)

* bpo-31149: Doc: Add Japanese to the language switcher. (python#3028)

(cherry picked from commit c82b7f3)

(cherry picked from commit e8e7fba)
vstinner pushed a commit that referenced this pull request Aug 13, 2017
#3051) (#3081)

* bpo-31159: fix language switch regex on unknown yet built languages. (#3039)

This fix a regex issue (a missing non-matching group around an 'or'
list) and the specific possible case where a translation is built but
not yet in known by the picker, but not explicitly listing possible
languages in the regex.
(cherry picked from commit 122081d)

* bpo-31149: Doc: Add Japanese to the language switcher. (#3028)

(cherry picked from commit c82b7f3)

(cherry picked from commit e8e7fba)
@JulienPalard JulienPalard deleted the doc-fix-switch branch June 16, 2019 14:02
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.

3 participants