Skip to content

Commit

Permalink
feat: extract multiple comments per translation ID (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertg authored Nov 12, 2020
1 parent 59b21bf commit c849c9c
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 60 deletions.
8 changes: 6 additions & 2 deletions packages/babel-plugin-extract-messages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const VISITED = Symbol("I18nVisited")
function addMessage(
path,
messages,
{ id, message: newDefault, origin, ...props }
{ id, message: newDefault, origin, comment, ...props }
) {
if (messages.has(id)) {
const message = messages.get(id)
Expand All @@ -33,9 +33,13 @@ function addMessage(
}

;[].push.apply(message.origin, origin)
if (comment) {
;[].push.apply(message.extractedComments, [comment])
}
}
} else {
messages.set(id, { ...props, message: newDefault, origin })
const extractedComments = comment ? [comment] : []
messages.set(id, { ...props, message: newDefault, origin, extractedComments })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`@lingui/babel-plugin-extract-messages should extract Plural messages from JSX files when there's no Trans tag (integration) 1`] = `
Object {
{count, plural, one {# book} other {# books}}: Object {
extractedComments: Array [],
origin: Array [
Array [
jsx-without-trans.js,
Expand All @@ -16,7 +17,9 @@ Object {
exports[`@lingui/babel-plugin-extract-messages should extract all messages from JS files (macros) 1`] = `
Object {
Description: Object {
comment: description,
extractedComments: Array [
description,
],
origin: Array [
Array [
js-with-macros.js,
Expand All @@ -25,6 +28,7 @@ Object {
],
},
ID: Object {
extractedComments: Array [],
message: Message with id,
origin: Array [
Array [
Expand All @@ -34,6 +38,7 @@ Object {
],
},
ID Some: Object {
extractedComments: Array [],
message: Message with id some,
origin: Array [
Array [
Expand All @@ -43,6 +48,7 @@ Object {
],
},
Message: Object {
extractedComments: Array [],
origin: Array [
Array [
js-with-macros.js,
Expand All @@ -55,6 +61,7 @@ Object {
],
},
Values {param}: Object {
extractedComments: Array [],
origin: Array [
Array [
js-with-macros.js,
Expand All @@ -68,7 +75,9 @@ Object {
exports[`@lingui/babel-plugin-extract-messages should extract all messages from JS files 1`] = `
Object {
Description: Object {
comment: description,
extractedComments: Array [
description,
],
origin: Array [
Array [
js-without-macros.js,
Expand All @@ -77,6 +86,7 @@ Object {
],
},
ID: Object {
extractedComments: Array [],
message: Message with id,
origin: Array [
Array [
Expand All @@ -86,6 +96,7 @@ Object {
],
},
Message: Object {
extractedComments: Array [],
origin: Array [
Array [
js-without-macros.js,
Expand All @@ -94,6 +105,7 @@ Object {
],
},
Values {param}: Object {
extractedComments: Array [],
origin: Array [
Array [
js-without-macros.js,
Expand All @@ -107,6 +119,7 @@ Object {
exports[`@lingui/babel-plugin-extract-messages should extract all messages from JSX files (macros) 1`] = `
Object {
Hi, my name is {name}: Object {
extractedComments: Array [],
origin: Array [
Array [
jsx-with-macros.js,
Expand All @@ -115,6 +128,7 @@ Object {
],
},
Title: Object {
extractedComments: Array [],
origin: Array [
Array [
jsx-with-macros.js,
Expand All @@ -123,6 +137,7 @@ Object {
],
},
{count, plural, one {# book} other {# books}}: Object {
extractedComments: Array [],
origin: Array [
Array [
jsx-with-macros.js,
Expand All @@ -136,6 +151,7 @@ Object {
exports[`@lingui/babel-plugin-extract-messages should extract all messages from JSX files 1`] = `
Object {
Hi, my name is <0>{name}</0>: Object {
extractedComments: Array [],
origin: Array [
Array [
jsx-without-macros.js,
Expand All @@ -144,6 +160,7 @@ Object {
],
},
msg.default: Object {
extractedComments: Array [],
message: Hello World,
origin: Array [
Array [
Expand All @@ -157,7 +174,9 @@ Object {
],
},
msg.hello: Object {
comment: Description,
extractedComments: Array [
Description,
],
origin: Array [
Array [
jsx-without-macros.js,
Expand Down
Loading

1 comment on commit c849c9c

@vercel
Copy link

@vercel vercel bot commented on c849c9c Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.