<commit_before>module.exports = {
  input: [
    'frontend/js/**/*.{js,jsx}',
    'modules/**/*.{js,jsx}',
    '!frontend/js/vendor/**',
  ],
  output: './',
  options: {
    sort: true,
    func: {
      list: ['t'],
      extensions: ['.js', '.jsx'],
    },
    trans: {
      component: 'Trans',
      i18nKey: 'i18nKey',
      defaultsKey: 'defaults',
      extensions: ['.js', '.jsx'],
      fallbackKey: false,
    },
    resource: {
      savePath: 'frontend/extracted-translations.json',
      jsonIndent: 2,
      lineEnding: '\n',
    },
  },
}<commit_msg>Add custom transform for extracting i18next keys from TypeScript files (#7138)<commit_after>const fs = require('node:fs')
const path = require('node:path')
const typescript = require('typescript')

module.exports = {
  input: [
    'frontend/js/**/*.{js,jsx,ts,tsx}',
    'modules/**/*.{js,jsx,ts,tsx}',
    '!frontend/js/vendor/**',
  ],
  output: './',
  options: {
    sort: true,
    func: {
      list: ['t'],
      extensions: ['.js', '.jsx'],
    },
    trans: {
      component: 'Trans',
      i18nKey: 'i18nKey',
      defaultsKey: 'defaults',
      extensions: ['.js', '.jsx'],
      fallbackKey: false,
    },
    resource: {
      savePath: 'frontend/extracted-translations.json',
      jsonIndent: 2,
      lineEnding: '\n',
    },
  },
  // adapted from https://github.com/nucleartux/i18next-scanner-typescript/blob/master/src/index.js
  transform: function (file, enc, done) {
    const { base, ext } = path.parse(file.path)

    if (['.ts', '.tsx'].includes(ext) && !base.endsWith('.d.ts')) {
      const content = fs.readFileSync(file.path, enc)

      const { outputText } = typescript.transpileModule(content, {
        compilerOptions: { target: 'es2018', jsx: 'preserve' },
        fileName: base,
      })

      this.parser.parseTransFromString(outputText)
      this.parser.parseFuncFromString(outputText)
    }

    done()
  },
}
{'fraction_non_alphanumeric': 0.1921875, 'fraction_numerical': 0.011458333333333333, 'mean_word_length': 2.6177024482109226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5986563', 'n_tokens_mistral': 692, 'n_tokens_neox': 670, 'n_words': 120}