I’ve been mulling over ways rustdoc could be improved for a while, and I’ve had some thoughts. Three in particular strike me as applicable:
-
Allow “inner attributes” on doc comments, which apply to the doc comment itself.
-
Add support for a #[doc(include(path="file.md"))] attribute for pulling doc material from an external file.
-
Add #[doc(locale="fr-FR")] attribute for flagging specific bits of documentation as only applying to a given locale.
So, at that point, you could do something like:
/**
#![locale="en-AU"]
This function is awesome!
*/
/**
#![locale="jp-JP"]
この関数は素晴らしいです!
*/
fn awesome() { println!("awesome!"); }
Of course, you probably don’t want source files to be reams and reams of documentation with the code buried in between, hence:
/**
#![locale="en-AU"]
This function is awesome!
*/
#[doc(include(path="awesome.md", section="awesome.jp-JP", locale="jp-JP"))]
fn awesome() { println!("awesome!"); }
With awesome.md:
# awesome.jp-JP
この関数は素晴らしいです!
This way, the documentation for the primary maintenance language can be in the source, with everything else in a separate file. Keeping the two in sync might be assisted by giving rustdoc the ability to spit out a list of things documented and a digest of their “primary language” documentation. That way, translations can include the hash of the documentation they were translated from; a tool can then warn you when translations need to be re-checked.
Also, I’m not saying Markdown is the best (or even appropriate) structure for this, and it would be even nicer if you could just import a whole .md file which contained appropriate locale annotations… but this is Markdown, so we might have to make do.