-
Notifications
You must be signed in to change notification settings - Fork 744
Enable localization #2123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enable localization #2123
Conversation
There was a problem hiding this 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
messageKeyandmessageArgsinstead of pre-formattedmessagestrings - This makes
.tsbuildinfofiles 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 |
There was a problem hiding this 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.
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
tsbuildinfolocale-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.tsfiles, 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.gzfiles; generating code like we do the diagnostic objects themselves, or even embedding.jsonfiles 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.