i18next-parser
i18next-parser copied to clipboard
VueLexer with a custom function list does not use the configured functions when parsing the script block of Vue SFC files
🐛 Bug Report
When using Vue SFC files with a custom VueLexer configuration specifying an array of supporting functions, the Vue Lexer does not look up the specified functions in the
I believe it happens because the JavascriptLexer instance that parses the
To Reproduce
- Use a vue SFC file as below
- Use custom Vue lexer configuration, that specifies extra functions (['t', '$t']).
<template>
<div>{{ $t('key1') }}</div>
</template>
<script>
export default {
data(){
return {
key2: this.$t('key2'),
key3: this.i18n.t('key3')
}
},
});
</script>
This is my VueLexer and JavascriptLexer configs:
const vueLexerConfig = {
lexer: 'VueLexer',
functions: ['t', '$t']
};
const javaScriptLexerConfig = {
lexer: 'JavascriptLexer',
functions: ['t', '$t']
};
...
lexers: {
hbs: ['HandlebarsLexer'],
handlebars: ['HandlebarsLexer'],
htm: ['HTMLLexer'],
html: ['HTMLLexer'],
mjs: [javaScriptLexerConfig],
js: [javaScriptLexerConfig],
ts: [javaScriptLexerConfig],
vue: [vueLexerConfig],
jsx: [javaScriptLexerConfig],
tsx: [javaScriptLexerConfig],
default: [javaScriptLexerConfig]
},
Expected behavior
All 3 keys - key1, key2, key3 are extracted to the locale json files.
Actual behavior
Only keys 'key1', 'key3' are extracted.
Your Environment
- runtime version: node - v16.15.1, i18next-parser - 6.4.0
Duplicate: https://github.com/i18next/i18next-parser/issues/262