Skip to content

Commit

Permalink
fix(cli): extract with --overwrite should fallback to key (#1166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardeois authored Nov 26, 2021
1 parent f665e39 commit e5e9d59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
23 changes: 21 additions & 2 deletions packages/cli/src/api/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,30 @@ describe("Catalog", function () {
message: "",
translation: "Message with custom ID",
}),
"Message with <0>auto-generated</0> ID": makePrevMessage({
translation: "Source of message with <0>auto-generated</0> ID",
}),
},
cs: {
"custom.id": makePrevMessage({
message: "",
translation: "Translation of message with custom ID",
}),
"Message with <0>auto-generated</0> ID": makePrevMessage({
translation: "Translation of message with auto-generated ID",
}),
},
}

const nextCatalog = {
"custom.id": makeNextMessage({
message: "Message with custom ID, possibly changed",
}),
"Message with <0>auto-generated</0> ID": makeNextMessage(),
}

// Without `overwrite`:
// The translation of `custom.id` message for `sourceLocale` is kept intact
// The translations of all IDs for `sourceLocale` are kept intact
expect(
makeCatalog({ sourceLocale: "en" }).merge(
prevCatalogs,
Expand All @@ -359,17 +366,23 @@ describe("Catalog", function () {
message: "Message with custom ID, possibly changed",
translation: "Message with custom ID",
}),
"Message with <0>auto-generated</0> ID": expect.objectContaining({
translation: "Source of message with <0>auto-generated</0> ID",
}),
},
cs: {
"custom.id": expect.objectContaining({
message: "Message with custom ID, possibly changed",
translation: "Translation of message with custom ID",
}),
"Message with <0>auto-generated</0> ID": expect.objectContaining({
translation: "Translation of message with auto-generated ID",
}),
},
})

// With `overwrite`
// The translation of `custom.id` message for `sourceLocale` is changed
// The translations of all IDs for `sourceLocale` are changed
expect(
makeCatalog({ sourceLocale: "en" }).merge(prevCatalogs, nextCatalog, {
overwrite: true,
Expand All @@ -380,12 +393,18 @@ describe("Catalog", function () {
message: "Message with custom ID, possibly changed",
translation: "Message with custom ID, possibly changed",
}),
"Message with <0>auto-generated</0> ID": expect.objectContaining({
translation: "Message with <0>auto-generated</0> ID",
}),
},
cs: {
"custom.id": expect.objectContaining({
message: "Message with custom ID, possibly changed",
translation: "Translation of message with custom ID",
}),
"Message with <0>auto-generated</0> ID": expect.objectContaining({
translation: "Translation of message with auto-generated ID",
}),
},
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class Catalog {
options.overwrite)

const translation = updateFromDefaults
? nextCatalog[key].message
? nextCatalog[key].message || key
: prevCatalog[key].translation

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[` 1`] = `
Object {
message_with_id: Object {
comments: Array [],
context: null,
extractedComments: Array [],
flags: Array [],
obsolete: false,
Expand All @@ -12,6 +13,7 @@ Object {
},
message_with_id_but_without_translation: Object {
comments: Array [],
context: null,
extractedComments: Array [
Comment made by the developers.,
],
Expand All @@ -22,6 +24,7 @@ Object {
},
{anotherCount, plural, one {Singular case} other {Case number {anotherCount}}}: Object {
comments: Array [],
context: null,
extractedComments: Array [],
flags: Array [],
obsolete: false,
Expand All @@ -30,6 +33,7 @@ Object {
},
{count, plural, one {Singular} other {Plural}}: Object {
comments: Array [],
context: null,
extractedComments: Array [],
flags: Array [],
obsolete: false,
Expand Down

0 comments on commit e5e9d59

Please sign in to comment.