Skip to content
This repository was archived by the owner on Feb 22, 2026. It is now read-only.
Open
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
3 changes: 2 additions & 1 deletion src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class i18nTransform extends Transform {
skipDefaultValues: false,
customValueTemplate: null,
failOnWarnings: false,
ignoreContext: false,
}

this.options = { ...this.defaults, ...options }
Expand Down Expand Up @@ -314,7 +315,7 @@ export default class i18nTransform extends Transform {
}

addEntry(entry) {
if (entry.context) {
if (!this.options.ignoreContext && entry.context) {
const contextEntry = Object.assign({}, entry)
delete contextEntry.context
contextEntry.key += this.options.contextSeparator + entry.context
Expand Down
25 changes: 25 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,31 @@ describe('parser', () => {
})
})

describe('ignoreContext', () => {
it('adds entry without context', (done) => {
let result
const i18nextParser = new i18nTransform({ ignoreContext: true })
const fakeFile = new Vinyl({
contents: Buffer.from("t('first', {context: 'female'})"),
path: 'file.js',
})

i18nextParser.on('data', (file) => {
if (file.relative.endsWith(enLibraryPath)) {
result = JSON.parse(file.contents)
}
})
i18nextParser.once('end', () => {
assert.deepEqual(result, {
first: '',
})
done()
})

i18nextParser.end(fakeFile)
})
})

it('handles output with $LOCALE and $NAMESPACE var', (done) => {
let result
const i18nextParser = new i18nTransform({
Expand Down