Skip to content

Commit 60b3338

Browse files
committed
Handle normalization where old msgid disappears
1 parent c35f3bb commit 60b3338

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/bin/mdbook-i18n-normalize.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ pub fn normalize(catalog: Catalog) -> anyhow::Result<Catalog> {
172172
let mut new_messages = Vec::new();
173173
for message in catalog.messages() {
174174
let new_msgids = source_map.extract_messages(message, MessageField::Msgid)?;
175+
if new_msgids.is_empty() {
176+
// Continue if there is nothing to normalize. This can
177+
// happen if the old `msgid` is something like "<b>Foo"
178+
// since we no longer extract HTML elements.
179+
continue;
180+
}
181+
175182
let mut new_msgstrs = source_map.extract_messages(message, MessageField::Msgstr)?;
176183
let mut flags = MessageFlags::new();
177184
if message.is_fuzzy() || (message.is_translated() && new_msgids.len() != new_msgstrs.len())
@@ -458,6 +465,13 @@ mod tests {
458465
);
459466
}
460467

468+
#[test]
469+
fn test_normalize_disappearing_html() {
470+
// Normalizing "<b>" results in no messages.
471+
let catalog = create_catalog(&[("<b>", "FOO")]);
472+
assert_normalized_messages_eq(catalog, &[]);
473+
}
474+
461475
#[test]
462476
fn test_normalize_code_blocks() {
463477
let catalog = create_catalog(&[(

0 commit comments

Comments
 (0)