-
Notifications
You must be signed in to change notification settings - Fork 415
fix(compile): remove verbose output when using template (*.pot) #1388
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
Merged
andrii-bodnar
merged 1 commit into
lingui:main
from
timofei-iatsenko:fix/verbose-logging-with-pot-file
Feb 6, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CLI Command: Compile Locales Validation Should throw error for invalid locale 1`] = ` | ||
Error: Invalid locale abra (missing plural rules)! | ||
|
||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show error and stop compilation of catalog if message doesnt have a translation (with template) 1`] = ` | ||
Object { | ||
en: /*eslint-disable*/module.exports={messages:JSON.parse("{\\"Hello World\\":\\"Hello World\\"}")};, | ||
pl: undefined, | ||
} | ||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show error and stop compilation of catalog if message doesnt have a translation (with template) 2`] = ` | ||
Error: Failed to compile catalog for locale pl! | ||
Missing 1 translation(s) | ||
|
||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show error and stop compilation of catalog if message doesnt have a translation (no template) 1`] = ` | ||
Error: Failed to compile catalog for locale pl! | ||
Missing 1 translation(s) | ||
|
||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show missing messages verbosely when verbose = true 1`] = ` | ||
en ⇒ /test/en.js | ||
Error: Failed to compile catalog for locale pl! | ||
Missing translations: | ||
Hello World | ||
Test String | ||
|
||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
import {command} from "../lingui-compile" | ||
import {makeConfig} from "@lingui/conf" | ||
import path from "path" | ||
import {getConsoleMockCalls, mockConsole} from "@lingui/jest-mocks" | ||
import mockFs from "mock-fs" | ||
import fs from 'fs' | ||
|
||
function readFsToJson(directory: string, filter?: (filename: string) => boolean) { | ||
const out = {} | ||
|
||
fs | ||
.readdirSync(directory) | ||
.map((filename) => { | ||
const filepath = path.join(directory, filename) | ||
|
||
if (fs.lstatSync(filepath).isDirectory()) { | ||
out[filename] = readFsToJson(filepath) | ||
return out | ||
} | ||
|
||
if (!filter || filter(filename)) { | ||
out[filename] = fs.readFileSync(filepath).toString() | ||
} | ||
}) | ||
|
||
return out | ||
} | ||
|
||
describe('CLI Command: Compile', () => { | ||
xit('Should return error if no messages', () => { | ||
const config = makeConfig({ | ||
locales: ['en', 'pl'], | ||
rootDir: path.join(__dirname, 'fixtures/compile'), | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'] | ||
}] | ||
}) | ||
|
||
const result = command(config, {}) | ||
expect(result).toBeFalsy() | ||
}) | ||
|
||
describe('Merge Catalogs', () => { | ||
// todo | ||
}) | ||
andrii-bodnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe('Locales Validation', () => { | ||
// todo: should be moved to @lingui/conf | ||
it('Should throw error for invalid locale', () => { | ||
const config = makeConfig({ | ||
locales: ['abra'], | ||
rootDir: '/test', | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'], | ||
exclude: [] | ||
}] | ||
}) | ||
|
||
mockFs() | ||
|
||
mockConsole((console) => { | ||
const result = command(config, {}) | ||
mockFs.restore() | ||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
|
||
expect(result).toBeTruthy() | ||
}) | ||
}) | ||
|
||
it('Should not throw error for pseudolocale', () => { | ||
const config = makeConfig({ | ||
locales: ['abracadabra'], | ||
rootDir: '/test', | ||
pseudoLocale: 'abracadabra', | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'], | ||
exclude: [] | ||
}] | ||
}) | ||
|
||
mockFs() | ||
|
||
mockConsole((console) => { | ||
const result = command(config, {}) | ||
mockFs.restore() | ||
expect(console.error).not.toBeCalled() | ||
expect(result).toBeTruthy() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('allowEmpty = false', () => { | ||
const config = makeConfig({ | ||
locales: ['en', 'pl'], | ||
sourceLocale: 'en', | ||
rootDir: '/test', | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'], | ||
exclude: [] | ||
}] | ||
}) | ||
|
||
it('Should show error and stop compilation of catalog ' + | ||
'if message doesnt have a translation (no template)', () => { | ||
mockFs({ | ||
'/test': { | ||
'en.po': ` | ||
msgid "Hello World" | ||
msgstr "Hello World" | ||
`, | ||
'pl.po': ` | ||
msgid "Hello World" | ||
msgstr "Cześć świat" | ||
|
||
msgid "Test String" | ||
msgstr "" | ||
` | ||
} | ||
}) | ||
|
||
mockConsole((console) => { | ||
const result = command(config, { | ||
allowEmpty: false | ||
}) | ||
const actualFiles = readFsToJson('/test') | ||
|
||
expect(actualFiles['pl.js']).toBeFalsy() | ||
expect(actualFiles['en.js']).toBeTruthy() | ||
mockFs.restore() | ||
|
||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
expect(result).toBeFalsy() | ||
}) | ||
}) | ||
|
||
it('Should show error and stop compilation of catalog ' + | ||
' if message doesnt have a translation (with template)', () => { | ||
mockFs({ | ||
'/test': { | ||
'messages.pot': ` | ||
msgid "Hello World" | ||
msgstr "" | ||
`, | ||
'pl.po': `` | ||
} | ||
}) | ||
|
||
mockConsole((console) => { | ||
const result = command(config, { | ||
allowEmpty: false | ||
}) | ||
|
||
const actualFiles = readFsToJson('/test') | ||
|
||
expect({ | ||
pl: actualFiles['pl.js'], | ||
en: actualFiles['en.js'] | ||
}).toMatchSnapshot() | ||
|
||
mockFs.restore() | ||
|
||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
expect(result).toBeFalsy() | ||
}) | ||
}) | ||
|
||
|
||
it('Should show missing messages verbosely when verbose = true', () => { | ||
mockFs({ | ||
'/test': { | ||
'pl.po': ` | ||
msgid "Hello World" | ||
msgstr "" | ||
|
||
msgid "Test String" | ||
msgstr "" | ||
` | ||
} | ||
}) | ||
|
||
mockConsole((console) => { | ||
const result = command(config, { | ||
allowEmpty: false, | ||
verbose: true | ||
}) | ||
|
||
mockFs.restore() | ||
|
||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
expect(result).toBeFalsy() | ||
}) | ||
}) | ||
|
||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.