Skip to content

Fix get_tokenizer rejecting BCP-47 locale tags like en-US - #2906

Open
kevin9327 wants to merge 1 commit into
openai:mainfrom
kevin9327:fix/tokenizer-bcp47-locale-tags
Open

kevin9327 wants to merge 1 commit into
openai:mainfrom
kevin9327:fix/tokenizer-bcp47-locale-tags

Conversation

@kevin9327

Copy link
Copy Markdown

Summary

get_tokenizer(..., language=...) accepted ISO 639 codes (en) and a few language names (english, mandarin), but rejected the locale tags users commonly pass from system locales and web APIs (en-US, zh-CN, pt_BR). That also broke English-only tokenizers, which ignore the language after validation and still raised Unsupported language.

This resolves a tag to its primary subtag when that subtag is a supported Whisper language (or a known alias), and leaves an unknown tag as an error.

Tests

Added regression tests in tests/test_tokenizer.py for hyphen and underscore locale tags, language-name aliases, unknown tags, and the English-only tokenizer path.

PYTHONPATH=. pytest tests/test_tokenizer.py tests/test_normalizer.py tests/test_audio.py -q
# 21 passed

(tests/test_timing.py CUDA cases were skipped; this environment has no NVIDIA driver.)

Locale tags such as en-US, zh-CN, or pt_BR previously raised
Unsupported language even though the primary language is supported.
Resolve them to the matching Whisper language code, including on
English-only tokenizers that otherwise ignore the language argument.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T03:51:15.532817Z 4615b62 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant