vue-i18n-extract: Does not actually remove keys

When i run npx vue-i18n-extract report --remove --vueFiles './src/components/**/*.?(js|vue)' --languageFiles './i18n/*.json' on my codebase the report correctly identifies the unused keys and says it would delete them but doesn’t actually do it.

About this issue

Most upvoted comments

So here’s the issue on my side: my language files are simple key-value pairs in dot notation (hereafter “flat file”):

{
    "foo.bar": "Hello world",
    "foo.baz": "Goodbye",
    "foo.qux": "Thankyou"
}

vue-extract-i18n expects language files to be hierarchical instead (hereafter “hierarchical file”):

{
    "foo": {
        "bar": "Hello world",
        "baz": "Goodbye",
        "qux": "Thankyou"
    }
}

Internally, vue-i18n-extract uses the dot-object library to convert the hierarchical format to the flat data model.

The report creation accidentally works on “flat” language files because Dot.dot is a no-op on them. But when vue-i18n-extract tries to actually remove the key, it calls Dot.delete on the flat file, which does not work, as Dot expect a hierarchical file.

Vue-i18n-extract’s code does not check the return value from Dot.delete, so it does not notice that it did not actually delete anything.

Works for me. Would be nice if you could give the link to the existing source(best if it would be codesandbox or similar)

You can try with this repo https://github.com/WeakAuras/WeakAuras-Companion