Skip to content
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

Zero output on scanner #239

Open
Chriskuiper1 opened this issue Dec 11, 2022 · 0 comments
Open

Zero output on scanner #239

Chriskuiper1 opened this issue Dec 11, 2022 · 0 comments

Comments

@Chriskuiper1
Copy link

Chriskuiper1 commented Dec 11, 2022

Hi I'm trying to implement i18next-scanner. So far I have npm installed i18next-scanner, created a config and npm script in my package.json. I have tested the config, it runs and creates a i18n folder in my project root with my project locales, but the json files are empty.

In my public folder -> locales -> {{lng}} -> {{ns}} are around 100 dummy translations, that have been translated with locize - their save missing feature could find all my non translated words. Sooo I don't really know what is wrong.

Can anyone help me out? If you need more information, just ask!

Execute command: i18next-scanner --config i18next-scanner.config.js

Thanks and regards from Chris


i18next-scanner.config.js

`
const fs = require('fs')
const chalk = require('chalk')

module.exports = {
input: [
'./src//*.{js,jsx}',
'./pages/
/.{js,jsx}',
// Use ! to filter out files or directories
'!./**/
.spec.{js,jsx}',
'!./i18n/',
'!
/node_modules/**'
],
output: './',
options: {
debug: true,
func: {
list: ['i18next.t', 'i18n.t'],
extensions: ['.js', '.jsx']
},
trans: {
component: 'Trans',
i18nKey: 'i18nKey',
defaultsKey: 'defaults',
extensions: ['.js', '.jsx'],
fallbackKey: function (ns, value) {
return value
},
// https://react.i18next.com/latest/trans-component#usage-with-simple-html-elements-like-less-than-br-greater-than-and-others-v10.4.0
supportBasicHtmlNodes: true, // Enables keeping the name of simple nodes (e.g.
) in translations instead of indexed keys.
keepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'], // Which nodes are allowed to be kept in translations during defaultValue generation of .
// https://github.com/acornjs/acorn/tree/master/acorn#interface
acorn: {
ecmaVersion: 2020,
sourceType: 'module' // defaults to 'module'
}
},
lngs: ['en', 'fr', 'nl', 'de'],
ns: ['locale', 'resource'],
defaultLng: 'en',
defaultNs: 'resource',
defaultValue: 'STRING_NOT_TRANSLATED',
resource: {
loadPath: './public/locales/{{lng}}/{{ns}}.json',
savePath: 'i18n/{{lng}}/{{ns}}.json',
jsonIndent: 2,
lineEnding: '\n'
},
nsSeparator: ':',
keySeparator: '.',
pluralSeparator: '',
contextSeparator: '
',
contextDefaultValues: [],
interpolation: {
prefix: '{{',
suffix: '}}'
},
metadata: {},
allowDynamicKeys: false
},
transform: function customTransform(file, enc, done) {
'use strict'
const parser = this.parser
const content = fs.readFileSync(file.path, enc)
let count = 0
parser.parseFuncFromString(content, { list: ['i18next._', 'i18next.__'] }, (key, options) => {
parser.set(
key,
Object.assign({}, options, {
nsSeparator: false,
keySeparator: false
})
)
++count
})
if (count > 0) {
console.log('i18next-scanner: count=${chalk.cyan(count)}, file=${chalk.yellow(JSON.stringify(file.relative))}')
}
done()
}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant