Skip to content

Commit

Permalink
Wrap the source lines like msgmerge does
Browse files Browse the repository at this point in the history
This will reduce churn between the output of `mdbook-xgettext` and
`msgmerge`. See google/comprehensive-rust#1245
for an example PR which would shrink with this feature.

Part of #32, but we still have differences in the way the messages
themselves are wrapped.
  • Loading branch information
mgeisler committed Oct 2, 2023
1 parent 5e8f203 commit e680e80
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions i18n-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pulldown-cmark-to-cmark = "11.0.0"
regex = "1.9.4"
semver = "1.0.16"
serde_json = "1.0.91"
textwrap = { version = "0.16.0", default-features = false }

[dev-dependencies]
pretty_assertions = "1.3.0"
Expand Down
5 changes: 4 additions & 1 deletion i18n-helpers/src/bin/mdbook-xgettext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ use polib::metadata::CatalogMetadata;
use std::{fs, io};

fn add_message(catalog: &mut Catalog, msgid: &str, source: &str) {
let wrap_options = textwrap::Options::new(76)
.break_words(false)
.word_splitter(textwrap::WordSplitter::NoHyphenation);
let sources = match catalog.find_message(None, msgid, None) {
Some(msg) => format!("{}\n{}", msg.source(), source),
Some(msg) => textwrap::refill(&format!("{}\n{}", msg.source(), source), wrap_options),
None => String::from(source),
};
let message = Message::build_singular()
Expand Down

0 comments on commit e680e80

Please sign in to comment.