Skip to content

Commit

Permalink
Merge pull request #107 from dyoo/refactor-messages
Browse files Browse the repository at this point in the history
Prepare `extract_messages` to return translator comments
  • Loading branch information
mgeisler authored Feb 20, 2024
2 parents 3012f1d + 5d87006 commit 35be9ad
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 57 deletions.
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/group_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fuzz_target!(|text: String| {
let flattened_groups = group_events(&events)
.into_iter()
.flat_map(|group| match group {
Group::Translate(events) | Group::Skip(events) => events,
Group::Translate { events, .. } | Group::Skip(events) => events,
})
.collect::<Vec<_>>();

Expand Down
12 changes: 6 additions & 6 deletions i18n-helpers/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::OnceLock;
#[derive(Debug, PartialEq)]
pub enum Directive {
Skip,
TranslatorComment(String),
Comment(String),
}

pub fn find(html: &str) -> Option<Directive> {
Expand All @@ -30,7 +30,7 @@ pub fn find(html: &str) -> Option<Directive> {
command.find("comment").unwrap() + "comment".len() + 1,
command.len(),
);
Some(Directive::TranslatorComment(
Some(Directive::Comment(
command[start_of_comment_offset..].trim().into(),
))
}
Expand Down Expand Up @@ -83,19 +83,19 @@ mod tests {
}

#[test]
fn test_translator_comment() {
fn test_comment() {
assert!(match find("<!-- i18n:comment: hello world! -->") {
Some(Directive::TranslatorComment(s)) => {
Some(Directive::Comment(s)) => {
s == "hello world!"
}
_ => false,
});
}

#[test]
fn test_translator_empty_comment_does_nothing() {
fn test_empty_comment_does_nothing() {
assert!(match find("<!-- i18n:comment -->") {
Some(Directive::TranslatorComment(s)) => {
Some(Directive::Comment(s)) => {
s.is_empty()
}
_ => false,
Expand Down
Loading

0 comments on commit 35be9ad

Please sign in to comment.