-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
diagnostics: translation infrastructure #95512
Conversation
Some changes occurred in src/tools/clippy. cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt. |
59753da
to
5386089
Compare
This comment has been minimized.
This comment has been minimized.
I'll wait for a review and feedback before fixing any CI failures, just in case any larger changes are required. |
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.
Overall looks quite good from an i18n standpoint! For the fluent stuff we probably want to support directories of ftl files, not just single large ftl files.
You can see what the website does here
/// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of | ||
/// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of | ||
/// diagnostic emission. | ||
pub type DiagnosticArg<'source> = (Cow<'source, str>, DiagnosticArgValue<'source>); |
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.
nit: probably worth making this a struct (tuple or otherwise)
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.
I'm deliberately using a tuple here because the FromIterator
impl on FluentArgs
works with this representation.
This is how I've implemented the user-requested language support, it loads every resource ( |
r? @oli-obk Taking over from Esteban to keep his queue from growing. Will sync separately with him on it |
This comment has been minimized.
This comment has been minimized.
b530be6
to
87654ac
Compare
This comment was marked as resolved.
This comment was marked as resolved.
87654ac
to
bb04e49
Compare
@bors r+ p=1 bitrotty |
📌 Commit bb04e494e2c237e5195b33fbdf4db1afb8ffb878 has been approved by |
⌛ Testing commit bb04e494e2c237e5195b33fbdf4db1afb8ffb878 with merge 4c269a7b4d2715f1379c500ff51ffc6f4aa6dd08... |
This comment was marked as outdated.
This comment was marked as outdated.
bb04e49
to
7d942f8
Compare
📌 Commit ccd4820 has been approved by |
Does it fallback to the default sysroot if |
It will only fail when it looks for a locale-specific directory in the sysroot and it isn't there, i.e. when the If that directory exists but doesn't contain any Fluent resources (or even anything that all), then it won't fail, it'll just always fallback to the default locale. If that directory contains Fluent resources which are empty, then it also won't fail, it'll just fallback to the default locale. In both of these cases we construct a I don't do anything different if it's a |
You might want to. Otherwise using xargo and other similar programs would cause translations to break as they don't add translations from the default sysroot to the created sysroot. |
Rollup of 5 pull requests Successful merges: - rust-lang#95234 (bootstrap.py: nixos check in /etc/os-release with quotes) - rust-lang#95449 (Fix `x doc --stage 0 compiler`) - rust-lang#95512 (diagnostics: translation infrastructure) - rust-lang#95607 (Note invariance reason for FnDef types) - rust-lang#95645 (Fix intra doc link ICE when trying to get traits in scope for primitive) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…t-only-warn, r=oli-obk sess: warn w/out fluent bundle w/ user sysroot Addresses rust-lang#95512 (comment). When a custom sysroot is requested, then don't error when translation resources are not found, only warn. r? `@bjorn3`
The documentation comment for this derive is out-of-date, it should have been updated in rust-lang#95512. Signed-off-by: David Wood <[email protected]>
…nor-changes, r=oli-obk errors: minor translation-related changes - For one error in typeck, specifying "suggestion" as the attribute for the only suggestion is unnecessary, it's the default of the derive. - The documentation comment for the `SessionDiagnostic` derive is out-of-date, it should have been updated in rust-lang#95512. r? `@oli-obk`
Can the approach be changed to maybe auto-generate the ftl file or something? Because I really like the experience of grepping for error messages and then directly getting to the code that creates the error. Now I'd have to figure out a fluent identifier, then I'd have to replace the |
Furthermore, it also makes contributor experience worse because you now have to edit one more file to add a new error/lint/etc. Sorry for posting to this pull request but I couldn't find any issue/rfc/etc linked, and wouldn't know how to get the attention of / reach the stakeholders otherwise. |
I've found something that looks like it could be the "canonical" issue for this: rust-lang/community-localization#4 It also looks like that initial plan included keeping the english error strings inside the rust source code. |
@est31 Let's chat about this in #t-compiler/wg-diagnostics :) |
Yeah, that was the initial plan, but tbh it's getting more and more rare to do in-source l10n strings. Sure it makes grepping a bit annoying but it really just means you have to grep twice instead of once. |
An implementation of the infrastructure required to have translatable diagnostic messages.
DiagnosticMessage
type which can represent both the current non-translatable messages and identifiers for Fluent.DiagnosticMessage
s can be provided too.DiagnosticMessage::FluentIdentifier
is used in a diagnostic being emitted.-Ztranslate-alternate-ftl
(for testing), or from the sysroot at$sysroot/locale/$locale/*.ftl
given a locale with-Ztranslate-lang
(which is parsed as a language identifier).#[derive(SessionDiagnostic)]
so that it can only be used for translatable diagnostics and update the handful of diagnostics which used the derive to be translatable.For example, the following diagnostic...
...becomes...
r? @estebank
cc @oli-obk @Manishearth