Skip to content

Commit

Permalink
Improve react support
Browse files Browse the repository at this point in the history
  • Loading branch information
karellm committed Mar 10, 2018
1 parent 998061d commit d5981d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export default class Parser extends EventEmitter {
constructor(options = {}) {
super(options)
this.options = options

if (options.reactNamespace) {
lexers.js = lexers.jsx
}

this.lexers = { ...lexers, ...options.lexers }
}

Expand Down
36 changes: 34 additions & 2 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,38 @@ describe('parser', () => {
i18nextParser.end(fakeFile)
})

it('parses Trans if reactNamespace is true', (done) => {
let result
const i18nextParser = new i18nTransform({
reactNamespace: true
})
const fakeFile = new Vinyl({
contents: fs.readFileSync(
path.resolve(__dirname, 'templating/react.jsx')
),
path: 'react.js'
})
const expected = {
first: '',
second: '',
third: 'Hello <strong title={t(\'fourth\')}>{{name}}</strong>, you have {{count}} unread message. <Link to="/msgs">Go to messages</Link>.',
fourth: ''
}

i18nextParser.on('data', file => {
// support for a default Namespace
if (file.relative.endsWith(path.normalize('en/react.json'))) {
result = JSON.parse(file.contents)
}
})
i18nextParser.on('end', () => {
assert.deepEqual(result, expected)
done()
})

i18nextParser.end(fakeFile)
})

it('supports outputing to yml', (done) => {
let result
const i18nextParser = new i18nTransform({
Expand Down Expand Up @@ -574,11 +606,11 @@ describe('parser', () => {
i18nextParser.end(fakeFile)
})

it('handles skipping the old catalog with createOldCatalog=false', (done) => {
it('handles skipping the old catalog with createOldCatalogs=false', (done) => {
let results = []
const i18nextParser = new i18nTransform({
defaultNamespace: 'default',
createOldCatalog: false
createOldCatalogs: false
})
const fakeFile = new Vinyl({
contents: Buffer.from(
Expand Down

0 comments on commit d5981d0

Please sign in to comment.