Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/js_macro_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ where
"id",
generate_message_id(
&parsed.message_str,
&(context_val.unwrap_or_default()),
context_val.as_deref().unwrap_or_default(),
)
.into(),
))
Expand All @@ -137,6 +137,19 @@ where
}
}

if !self.ctx.options.strip_non_essential_fields {
if let Some(context) = context_val {
new_props.push(create_key_value_prop("context", context.into()));
}

let comment = get_object_prop(&obj.props, "comment")
.and_then(|prop| get_expr_as_string(&prop.value));

if let Some(comment) = comment {
new_props.push(create_key_value_prop("comment", comment.into()));
}
}

let message_descriptor = Box::new(Expr::Object(ObjectLit {
span,
props: new_props,
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ where

let parsed = MessageBuilder::parse(trans_visitor.tokens);
let id_attr = get_jsx_attr(&el.opening, "id").and_then(|attr| attr.value.as_ref());

let context_attr =
get_jsx_attr(&el.opening, "context").and_then(|attr| attr.value.as_ref());

Expand Down Expand Up @@ -148,6 +149,14 @@ where
}

if !self.ctx.options.strip_non_essential_fields {
let comment_attr = get_jsx_attr(&el.opening, "comment")
.and_then(|attr| attr.value.as_ref())
.and_then(get_jsx_attr_value_as_string);

if let Some(comment) = comment_attr {
message_descriptor_props.push(create_key_value_prop("comment", comment.into()));
}

message_descriptor_props.push(create_key_value_prop("message", parsed.message));

if let Some(context_attr) = context_attr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const message = /*i18n*/ {
message: "{count, plural, one {book} other {books}}",
values: {
count: count
}
},
comment: "Description"
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const message = /*i18n*/ {
id: "custom.id",
message: "Message"
message: "Message",
comment: "Description"
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const message1 = /*i18n*/ {
id: "xDAtGP",
message: "Message"
message: "Message",
comment: "Description"
};
const message2 = /*i18n*/ {
id: "xDAtGP",
message: "Message"
message: "Message",
comment: "Description"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { i18n as $_i18n } from "@lingui/core";
const msg2 = $_i18n._(/*i18n*/ {
id: "msgId",
context: "My Context",
comment: "description for translators"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { i18n as $_i18n } from "@lingui/core";
const msg2 = $_i18n._(/*i18n*/ {
id: "msgId",
message: "Hello {name}",
values: {
name: name
},
context: "My Context",
comment: "description for translators"
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const msg = $_i18n._(/*i18n*/ {
message: "Hello {name}",
values: {
name: name
}
},
comment: "description for translators"
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ $_i18n._(/*i18n*/ {
});
$_i18n._(/*i18n*/ {
id: "7hFP9A",
message: "Ola"
message: "Ola",
context: "My Context"
});
$_i18n._(/*i18n*/ {
id: "7hFP9A",
message: "Ola"
message: "Ola",
context: "My Context"
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const msg = $_i18n._(/*i18n*/ {
message: "{val, plural, one {...} other {...}}",
values: {
val: val
}
},
comment: "description for translators"
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Trans as Trans_ } from "@lingui/react";
const exp2 = <Trans_ {.../*i18n*/ {
id: "6J8UtY",
comment: "Translators Comment",
message: "Refresh inbox",
context: "Message Context"
}} i18n="i18n" component={(p)=><div>{p.translation}</div>} render={(v)=>v}/>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Trans as Trans_ } from "@lingui/react";
values: {
count: count
},
comment: "Translators Comment",
message: "{count, plural, one {...} other {...}}",
context: "Message Context"
}} render={(v)=>v}/>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Trans as Trans_ } from "@lingui/react";
components: {
0: <strong/>
},
comment: "Translators Comment",
message: "{count, select, male {He} female {She} other {<0>Other</0>}}",
context: "Message Context"
}} render={(v)=>v}/>;
25 changes: 25 additions & 0 deletions tests/js_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ to!(
"#
);

to!(
js_should_produce_all_fields_without_strip_flag,
r#"
import { t } from '@lingui/core/macro'
const msg2 = t({
message: `Hello ${name}`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
})
"#
);

to!(
js_should_produce_all_fields_when_no_message_set,
r#"
import { t } from '@lingui/core/macro'
const msg2 = t({
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
})
"#
);

to!(
js_support_template_strings_in_t_macro_message_with_custom_i18n_instance,
r#"
Expand Down