Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extract multiple comments per translation ID #854

Merged
merged 6 commits into from
Nov 12, 2020
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
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