Skip to content

Commit 57433be

Browse files
committed
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.
1 parent 0f38d27 commit 57433be

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

scripts/patch-mdbook-theme.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ cat >> "$HEAD_HBS" << 'ENDSCRIPT'
8989
document.addEventListener('DOMContentLoaded', function() {
9090
var path = window.location.pathname;
9191
// Match both deployed (/coreutils/docs[-lang]/utils/X.html) and local (book[-lang]/utils/X.html)
92-
var match = path.match(/\/(?:coreutils\/)?docs(?:-([a-z]{2}(?:-[A-Z]{2})?))?\/utils\/(\w+)\.html/)
93-
|| path.match(/\/book(?:-([a-z]{2}(?:-[A-Z]{2})?))?\/utils\/(\w+)\.html/);
92+
var match = path.match(/\/(?:coreutils\/)?docs(?:-([a-zA-Z]{2}(?:-[a-zA-Z]+)?))?\/utils\/(\w+)\.html/)
93+
|| path.match(/\/book(?:-([a-zA-Z]{2}(?:-[a-zA-Z]+)?))?\/utils\/(\w+)\.html/);
9494
if (!match) return;
9595
9696
var currentLang = match[1] || 'en';

0 commit comments

Comments
 (0)