Fix language selector regex to match zh-Hant, zh-Hans, nb-NO, etc.

The URL matching regex only accepted two-letter codes or two-letter
plus two uppercase (e.g., pt-BR), missing codes like zh-Hant with
longer suffixes. Use [a-zA-Z]+ after the hyphen to match all codes.
This commit is contained in:
Sylvestre Ledru
2026-03-22 20:00:48 +01:00
parent 0f38d27854
commit 57433becaa
+2 -2
View File
@@ -89,8 +89,8 @@ cat >> "$HEAD_HBS" << 'ENDSCRIPT'
document.addEventListener('DOMContentLoaded', function() {
var path = window.location.pathname;
// Match both deployed (/coreutils/docs[-lang]/utils/X.html) and local (book[-lang]/utils/X.html)
var match = path.match(/\/(?:coreutils\/)?docs(?:-([a-z]{2}(?:-[A-Z]{2})?))?\/utils\/(\w+)\.html/)
|| path.match(/\/book(?:-([a-z]{2}(?:-[A-Z]{2})?))?\/utils\/(\w+)\.html/);
var match = path.match(/\/(?:coreutils\/)?docs(?:-([a-zA-Z]{2}(?:-[a-zA-Z]+)?))?\/utils\/(\w+)\.html/)
|| path.match(/\/book(?:-([a-zA-Z]{2}(?:-[a-zA-Z]+)?))?\/utils\/(\w+)\.html/);
if (!match) return;
var currentLang = match[1] || 'en';