Skip to content

Commit

Permalink
fix: Allow empty translations for pseudo locale in compile --strict (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fdev authored Dec 23, 2024
1 parent 099820a commit 8cae5e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/lingui-compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function command(
},
})

if (!options.allowEmpty && missingMessages.length > 0) {
if (!options.allowEmpty && locale !== config.pseudoLocale && missingMessages.length > 0) {
console.error(
chalk.red(
`Error: Failed to compile catalog for locale ${chalk.bold(locale)}!`
Expand Down
39 changes: 38 additions & 1 deletion packages/cli/src/test/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ describe("CLI Command: Compile", () => {
// todo
})

function getConfig(rootDir: string) {
function getConfig(rootDir: string, pseudoLocale?: string) {
return makeConfig({
locales: ["en", "pl"],
sourceLocale: "en",
pseudoLocale: pseudoLocale,
rootDir: rootDir,
catalogs: [
{
Expand Down Expand Up @@ -100,6 +101,42 @@ msgstr ""
}
)

it(
"Should allow empty translation for pseudo locale",
async () => {
expect.assertions(4)

const rootDir = await createFixtures({
"/test": {
"en.po": `
msgid "Hello World"
msgstr "Hello World"
`,
"pl.po": `
msgid "Hello World"
msgstr ""
`,
},
})

const config = getConfig(rootDir, 'pl')

await mockConsole(async (console) => {
const result = await command(config, {
allowEmpty: false,
})
const actualFiles = readFsToJson(config.rootDir)

expect(actualFiles["pl.js"]).toBeTruthy()
expect(actualFiles["en.js"]).toBeTruthy()

const log = getConsoleMockCalls(console.error)
expect(log).toBeUndefined()
expect(result).toBeTruthy()
})
}
)

it("Should show missing messages verbosely when verbose = true", async () => {
expect.assertions(2)
const rootDir = await createFixtures({
Expand Down

0 comments on commit 8cae5e0

Please sign in to comment.