Currently I have many logs by i18next
that make difficult to use the console:
I need i18next
to use warning level instead of default info level, in order to be able to filter them.
Im checking docs but I dont see any option. My current configuration is:
JavaScript
x
20
20
1
i18n
2
.use(XHR)
3
.use(LanguageDetector)
4
.init({
5
debug: true,
6
lng: 'en',
7
keySeparator: false,
8
addMissing: true,
9
interpolation: {
10
escapeValue: false
11
},
12
13
resources: {
14
en: {
15
translations: translationEng
16
},
17
ns: ['translations'],
18
defaultNS: 'translations'
19
})
20
Advertisement
Answer
You can disable debug: false
, which will disable the default console.log
stuff.
And and an event listener missingKey
on the i18n
instance.
JavaScript
1
24
24
1
i18n
2
.use(XHR)
3
.use(LanguageDetector)
4
.init({
5
debug: false, // <-- disable default console.log
6
lng: 'en',
7
keySeparator: false,
8
addMissing: true,
9
interpolation: {
10
escapeValue: false
11
},
12
13
resources: {
14
en: {
15
translations: translationEng
16
},
17
ns: ['translations'],
18
defaultNS: 'translations'
19
});
20
21
i18n.on('missingKey', (lng, namespace, key, fallbackValue) => {
22
console.warn(lng, namespace, key, fallbackValue);
23
})
24
Based on this code
Other option is to use the options.missingKeyHandler
to pass a custom handler for handing missing keys.
JavaScript
1
24
24
1
i18n
2
.use(XHR)
3
.use(LanguageDetector)
4
.init({
5
debug: false, // disable this
6
lng: 'en',
7
keySeparator: false,
8
addMissing: true,
9
interpolation: {
10
escapeValue: false
11
},
12
13
resources: {
14
en: {
15
translations: translationEng
16
},
17
ns: ['translations'],
18
defaultNS: 'translations',
19
saveMissing: true, // must be enabled
20
missingKeyHandler: (lng, ns, key, fallbackValue) => {
21
console.warn(lng, ns, key, fallbackValue)
22
}
23
})
24
Based on this code