Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Nov 18, 2025

This PR enables localization, both for CLI with --locale, but also for in the language server via the client-provided locale init option.

To make this happen, we needed to stop eagerly formatting diagnostic messages. The reason this worked in the old codebase was because we used a global locale, so any time we made a diag, it happened to be produce after the global locale was set.

Doing that again sounds like an utter nightmare to test, so instead I make diagnostics remember their "message key" and stringified args. Then, when we finally go to produce the diagnostics, we then use the locale available to us to finalize the messsage.

Interestingly, this also makes tsbuildinfo locale-invariant, which is nice.

I also had to sort of redo the JSX element message hack; we were eagerly resolving a message to remove its placeholders, turning that into another *diagnostic.Message, and then passing that into relations. That doesn't work so well, so it's been replaced with something that seems to produce equivalent errors.

Localization files are currently just embedded into the binary. I would like to use a system similar to what we do with .d.ts files, but there's a notable difference between them. The lib files need to be in the filesystem, so we use an FS wrapper to provide them, or use a real disk path. But for diagnostics, we really don't want to have to lug an FS around to where diags are localized (at least, that seems bad), so reusing the existing infra is not so great.

The localization files are .json.gz files; generating code like we do the diagnostic objects themselves, or even embedding .json files in a similar format to the old codebase would increase the binary size by some 5MB. No good!

What is here I think is the least bad balance until I can refactor the bundled-file system to better handle localizations.

Copilot AI review requested due to automatic review settings November 18, 2025 22:59
Copilot finished reviewing on behalf of jakebailey November 18, 2025 23:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables localization support for both CLI (via --locale) and the language server (via client-provided locale). The key architectural change is that diagnostic messages are no longer eagerly formatted; instead, they store their message key and stringified arguments, which are formatted only when diagnostics are finally produced using the available locale.

Key changes:

  • Diagnostics now store messageKey and messageArgs instead of pre-formatted message strings
  • This makes .tsbuildinfo files locale-invariant
  • Added locale support infrastructure to the parse config host

Reviewed Changes

Copilot reviewed 113 out of 141 changed files in this pull request and generated no comments.

File Description
Multiple baseline .js files Updated test baselines showing the new diagnostic format in .tsbuildinfo files with messageKey and messageArgs replacing message
internal/tsoptions/tsoptionstest/vfsparseconfighost.go Added TheLocale field and Locale() method to support localization in test infrastructure

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 124 out of 153 changed files in this pull request and generated 4 comments.

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