Skip to content

Show the proper title of the programming language in code samples - #5896

Merged
Eugene (OEvgeny) merged 5 commits into
mainfrom
OEvgeny/fix-code-block-language-title
Oct 18, 2026
Merged

Eugene (OEvgeny) merged 5 commits into
mainfrom
OEvgeny/fix-code-block-language-title

Conversation

@OEvgeny

@OEvgeny Eugene (OEvgeny) commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Code samples show the programming language as sent by the bot, with only the first letter capitalized, e.g. "Javascript" instead of "JavaScript" (follow-up to #5893).

Changelog Entry

Fixed

  • Fixed code samples, such as in the "View code" dialog, titled "Javascript" instead of "JavaScript": common programming languages and their aliases, such as js, now show their proper names, which can be overridden via overrideLocalizedStrings (PROGRAMMING_LANGUAGE_*), in PR #5896, by @OEvgeny
  • Fixed code not being highlighted when the programming language is not in lowercase, such as TS, in PR #5896, by @OEvgeny

Description

The titles of collapsible code blocks and of the "View code" dialog were the raw programmingLanguage of the message, capitalized only by CSS, so javascript showed as "Javascript" and the dialog was labelled "Code sample: javascript". Common languages and their aliases (case-insensitive) now map to localizable titles, e.g. js to "JavaScript" and py to "Python"; other languages, such as bash, keep their first letter capitalized. The language is also lower-cased for the highlighter, so TS is highlighted like ts.

Design

  • Titles are localizable strings (PROGRAMMING_LANGUAGE_*), so hosts can override them via overrideLocalizedStrings; languages whose title is just the capitalized name, such as Go, have no string.
  • Names and aliases follow Shiki's language list, which is not imported: it would add every grammar to the bundle.
  • Open question: should programming language names go through translation at all?

Specific Changes

  • component/src/hooks/internal/useLocalizeProgrammingLanguage.ts: new internal hook that maps a language or alias to its localized title
  • StackedLayout.tsx and MarkdownTextContent.tsx: use the hook for the titles of the code block and the "View code" dialog
  • CodeBlockContent.module.css and ViewCodeDialog.module.css: removed the text-transform capitalization
  • api/src/localization/en-US.json: added 20 PROGRAMMING_LANGUAGE_* strings
  • bundle/src/codeHighlighter/ShikiComposer.tsx: lower-cases the language before highlighting
  • Added __tests__/html2/activity/programmingLanguageTitle.html: lowercase, uppercase, alias, overridden, and unknown languages in collapsible code blocks and the "View code" dialog
  • Updated the markdown/codeBlock/contrast* and activity/collapsible* snapshots, which also pick up the final comment color from Ensure 4.5:1 contrast for syntax-highlighted code and keep code blocks when messages are already in the store #5893
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

Eugene Olonov added 4 commits October 18, 2026 00:03
Map common programming languages and their aliases (case-insensitive) to
localizable titles, e.g. "js" to "JavaScript", instead of capitalizing
the first letter of the raw value via CSS. Titles can be overridden via
overrideLocalizedStrings (PROGRAMMING_LANGUAGE_*); unknown languages keep
their first letter capitalized.
…ht case-insensitively

- "bash" and "zsh" keep their own name instead of "Shell" (as before this PR)
- Drop PROGRAMMING_LANGUAGE_C/GO/JAVA/SWIFT: no aliases, same as the fallback
- Comment every PROGRAMMING_LANGUAGE_* string, like other grouped strings
- Lower-case the language before Shiki resolves it, so "TS" is highlighted
- Re-capture markdown/codeBlock/contrast{,.fluent,.fluent.dark} snap-3 with
  the current comment color (#656d76)
The title is now "Python" in the DOM instead of "python" upper-cased by a
`::first-letter` rule, so the browser shapes it as one text run and the
anti-aliasing of the "t" differs in 6 pixels. Re-capture snap-8 and snap-9
of part-grouping/{fluent,fluent.dark,copilot,copilot.dark}.html.
@OEvgeny
Eugene (OEvgeny) marked this pull request as ready for review October 18, 2026 18:09
Copilot AI balanced review requested due to automatic review settings October 18, 2026 18:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread __tests__/html2/activity/programmingLanguageTitle.html
@OEvgeny
Eugene (OEvgeny) merged commit aafe627 into main Oct 18, 2026
32 checks passed
@OEvgeny
Eugene (OEvgeny) deleted the OEvgeny/fix-code-block-language-title branch October 18, 2026 21:57
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