Skip to content

feat: Translatable diagnostics #19545

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Brayan-724
Copy link

This PR introduces infrastructure to make diagnostics in rust-analyzer translatable using Fluent.

Overview

  • Diagnostic messages are now externalized and identified by Fluent message IDs.
  • Adds basic integration with Fluent for message resolution.
  • No translations are included yet — this just sets up the system.

Motivation

Enables future localization of diagnostics, improving accessibility for non-English users. This is not focused on built-in localization, but forks with their own messages.

Next Steps

  • Add actual .ftl files for all the diagnostics.
  • Expand Fluent usage to other user-facing strings.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 8, 2025
@Brayan-724
Copy link
Author

This is a proof of concept, so please give me feedback to continue

Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

Feedback as an outsider to RA: If you're going to use fluent, it could be interesting seeing if rustc_fluent_macro could be added to auto-publish and have static checking support. Also, adding two whole modules just for fluent is probably not the most ergonomic solution.

@@ -10,8 +10,8 @@ pub(crate) fn await_outside_of_async(
let display_range =
adjusted_display_range(ctx, d.node, &|node| Some(node.await_token()?.text_range()));
Diagnostic::new(
crate::DiagnosticCode::RustcHardError("E0728"),
format!("`await` is used inside {}, which is not an `async` context", d.location),
crate::DiagnosticCode::RustcHardError(fluent_files::await_outside_of_async_code),
Copy link
Member

Choose a reason for hiding this comment

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

Rustc errors do not change with translations

@blyxyas
Copy link
Member

blyxyas commented Apr 9, 2025

Some concerns I brought up in Discord, I saw the PR before reading that it's meant to be forked:

  • If this is meant to be forked, how would the users get the forks? Would them download possibly unmaintained or with variable levels of quality? What if a maintainer stops maintaining their fork for whatever reason? The users would have to move to another fork.

  • If an user wants to have multiple languages, they'd need to change binaries in their toolchain directory, and they would unsync again after an update, we'd need to talk with Rustup.

The safest bet for implementing multilanguage solutions is letting the community create language packs and linking rust-analyzer against them. This would impact performance but if it's on server startup, I don't think that the time for parsing and integrating the error messages is that important.

I'm not sure if Rust wants to have 5-10 forks with variable levels of maintability (without accounting for a possible vector of attack, because we'll have to warn that they're user maintained and watch them closely to avoid someone making a fork that mines bitcoin in user's machines)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants