- Notifications
You must be signed in to change notification settings - Fork 556
new chapter with examples of diagnostic translation PRs #1621
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?
Changes from 1 commit
2b87b31 5c8febd bac43d0 d5201cd bcc1166 c7637de e5e5a9b 30a4d2b c0b491e 18fa8fb bbbd60d 637ebaa 7955bb3 ea7e58a 67af5ca 6f97f45 d9596c6 3389074 3678b50 04f3cf0 2557089 5c4b673 e305a42 6964f75 4b2f038 c1c84d6 81a4d04 df17432 1dee5f8 f979af6 af80d31 4c39d33 24de0fa 452b5ab d3daa1f 04e1702 8ee1ff5 47c8189 2512667 9334d59 0a80e53 f3fe248 0a61352 c2371da e81b583 18fc34b 1e7fe14 bedc610 b0a0a4f 9c9882c a240e52 1be023c d7832db 8ba0403 94a29d4 20e571f 2bf1b9a daca468 b5a632f 2a9f8fb c0c957c 04892c1 6b0a155 8593238 5be5475 a5363fb 5d8825e f29e38c c3232c4 6b3a5fb a605591 290ecb9 f1609a3 b21b0bb 39612f9 1f8cda6 f587d6e f349ee1 b8b984f 03752ab 27c2aa6 1c79085 7743f0f ed11720 1370793 de71812 882921a b8228e9 d3ce60f 57a38ad 0932ad6 9a86c04 509ee50 7518c34 e68dfb8 a8ccc26 736fcb9 0a2f713 a262476 6686b1e 51a37ad 7f426da bd8eeff 88bd6ca 94ecbac 03fe2d4 a6c35fc 43e4117 2bdb02c 0872241 090bd54 63b45c3 d0dc6c9 01a51b2 7354b42 39c10de 36e15ae 6f3d5e4 f98f1e5 32bc13e 0bd5bd1 2889c29 e85c4c4 af134d2 fa3ffbf 96462f2 c4e632e a7cd864 e269950 d3564ba d147c52 b145e1e 3b98da0 9f3efe6 1211eeb 1cf62dd 4c516b0 55c2c09 58077bf a213de4 8b42eb5 54e6f5b ba1db24 586474f e6fd600 8fa9ede fd9a461 f111b88 51fc2ec ef12db3 664346d b3e2a6e da0a4a0 d89d417 e67f3b8 e799c10 ec0d134 0dc2b03 de053e2 7352353 ea33f70 7313897 7d3c1c8 042c49c 757ad6d 5ecd75a b6cc460 0e18184 21c77d7 f4f78f7 0bcdb56 61771df 15bd9e4 9656b8c 7eaff60 167d22c 71766d9 c166632 566124f 54cfdd7 4a1d549 e359ee2 472188e ba809ff c42c13e c97f571 98cc718 5db974f 49c93f6 d8c298d d30be86 e0074c1 860162a bf4cdde d579acb 5c65222 2d1e71a 0591410 7e9449a ed5b175 33ea559 df5aee0 41a96ab 2ab6fbc 5eb8171 82257c2 c9e4cb7 77aaf99 fb4cc6f d0ee17f 74afdfc 4a86a8d df7970b fdacc77 2c113b3 c80a26f ed87804 4e8110c 1f4d6ac 91d8bbe 1a72161 64f1af1 6f536e4 8715e8f b328f82 727941f 5173d1f 84b9f4d 51dca6a 99b6b92 1efd0ad 095f27d 110275f ea01bf5 d01441d a7d9603 9d76913 b06dab8 2d0681e b684e35 62f03c2 82e50a6 4597bb4 d1d6ce8 7e50a6a 78c3edc 0650847 425b628 d95acf2 ca3e018 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,197 @@ | ||||||
| # Making diagnostics translatable | ||||||
| | ||||||
| <!-- toc --> | ||||||
| | ||||||
| There is an ongoing effort to make diagnostics translatable, | ||||||
| and the coordination happens [on GitHub]. | ||||||
| | ||||||
| This is intended to be a gentle guide to help with this effort, | ||||||
| with the use of examples. | ||||||
| | ||||||
| > A more detailed explanation can be found in [the announcement of the initiative]. | ||||||
| > However, | ||||||
| > note that some of the important details are now outdated. | ||||||
| > | ||||||
| > Reference documentation can be found in these chapters: | ||||||
| > - [Diagnostic structs](diagnostic-structs.md) | ||||||
| > - [Translation system](translation.md) | ||||||
| | ||||||
| ## General comments | ||||||
| | ||||||
| For a single diagnostic, 3 files need to be modified: | ||||||
| | ||||||
| - One file where the diagnostic is emitted, | ||||||
| typically by calling [Session::struct_span_err]. | ||||||
| - One file where the type representing the diagnostic, | ||||||
| typically a `struct`, would be added. | ||||||
| This would be in the `errors` module of the relevant rustc crate. | ||||||
tshepang marked this conversation as resolved. Outdated Show resolved Hide resolved | ||||||
| - One file where the actual text of the diagnostic is located, | ||||||
| located in a file named `locales/en-US.ftl`, | ||||||
| relative to the root path of the relevant rustc crate. | ||||||
| | ||||||
| ## Simple example | ||||||
| | ||||||
| *This uses [issue #108727] for demonstration* | ||||||
| | ||||||
| Suppose you have the following code: | ||||||
| | ||||||
| ```rust | ||||||
| ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit(); | ||||||
| ``` | ||||||
| | ||||||
| > Note that `ecx.struct_span_err` is the [Session::struct_span_err]. | ||||||
| ||||||
| > Note that `ecx.struct_span_err` is the [Session::struct_span_err]. | |
| > Note that `ecx.struct_span_err` calls [Session::struct_span_err]. |
This should also probably link to ecx.struct_span_err (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/base/struct.ExtCtxt.html#method.struct_span_err) so that users can attest this relationship themselves.
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.
yeah, that should have been ultimately calls...
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.
| - Replace the code above with this: | |
| - Replace the calls to `struct_span_err` and `emit` with: |
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.
Should point to emit_err in rustdocs. Also, useful to point out that if the user wants to make a diagnostic, but not emit it, they can use create_err.
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.
tough balance between adding useful info and avoiding the overwhelm... I should find a way to fit create_err in the reference
Outdated
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.
| - Create the above type, `errors::ProcMacroDeriveTokens`, | |
| - Add a diagnostic struct, `errors::ProcMacroDeriveTokens`, |
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 think it may be useful to motivate the three important parts of this:
derive(Diagnostic)diag(FLUENT_SLUG)- and
primary_span
Maybe why we need these three components, what other components are common, etc?
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 more wanted to have people see the pattern, than do wall-of-text which can overwhelm. The more complete details are in the reference chapters (earlier in the guide).
Uh oh!
There was an error while loading. Please reload this page.