lokalise / i18n-ally

🌍 All in one i18n extension for VS Code
https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally
MIT License
3.99k stars 322 forks source link

Add ability to find unused keys #765

Open ARZarkesh opened 2 years ago

ARZarkesh commented 2 years ago

Is your feature related to a specific framework or general for this extension

vue-i18n

Is your feature request related to a problem? Please describe.

-

Describe the solution you'd like

-

Additional context

I want this ability to find and remove unused keys to decrease locale files sizes.

robinsandstrom commented 2 years ago

Here is how I currently do it, begin with installing `i18next-scanner’ and then add the following config:

/** RUN WITH COMMAND: i18next-scanner **/
const fs = require('fs')
const chalk = require('chalk')
const input = [
  'src/modules/*.{htm,html,js,jsx,vue,ts}',
  'src/router/*.{htm,html,js,jsx,vue,ts}',
  'src/constants/*.{htm,html,js,jsx,vue,ts}',
  'src/composables/*.{htm,html,js,jsx,vue,ts}',
  'src/components/*.{htm,html,js,jsx,vue,ts}',
  'src/components/*/*.{htm,html,js,jsx,vue,ts}',
  'src/components/*/*/*.{htm,html,js,jsx,vue,ts}',
  'src/components/*/*/*/*.{htm,html,js,jsx,vue,ts}',
  'src/utils/*.{htm,html,js,jsx,vue,ts}',
  '!app/**/*.spec.{js,jsx}',
  '!app/i18n/**',
  '!**/node_modules/**',
]

module.exports = {
  input,
  output: './',
  options: {
    debug: true,
    func: {
      list: ['t'],
      extensions: ['.js', '.jsx', '.vue', '.html', '.htm', '.ts'],
    },
    trans: {
      component: 'Trans',
      extensions: [],
    },
    lngs: ['prx'],
    ns: ['locale'],
    defaultLng: 'en',
    defaultNs: 'locale',
    defaultValue: '__STRING_NOT_TRANSLATED__',
    resource: {
      loadPath: 'locales/{lng}.json',
      savePath: 'locales/{lng}.json',
      jsonIndent: 4,
      lineEnding: '\n',
    },
    nsSeparator: false,
    keySeparator: '.',
    interpolation: {
      prefix: '{',
      suffix: '}',
    }
  }
}

I added lngs: [prx], (where prx is just short for proxy). When I run i18next-scanner, all unused keys are added to prx.json and then I can add them to the languages I want translated directly in VS Code with i18n ally. If anyone has improvements I'd be happy to hear it. :)