Repository: electron-userland/electron-builder
File: packages/app-builder-lib/src/electron/ElectronFramework.ts (TypeScript)

Code before:
      await addWinAsarIntegrity(executable, options.asarIntegrity)
    }
  } else {
    await createMacApp(packager as MacPackager, appOutDir, options.asarIntegrity, (options.platformName as ElectronPlatformName) === "mas")
  }
  await removeUnusedLanguagesIfNeeded(options)
}

async function removeUnusedLanguagesIfNeeded(options: BeforeCopyExtraFilesOptions) {
  const {
    packager: { config, platformSpecificBuildOptions },
  } = options
  const wantedLanguages = asArray(platformSpecificBuildOptions.electronLanguages || config.electronLanguages)
  if (!wantedLanguages.length) {
    return
  }

  const { dirs, langFileExt } = getLocalesConfig(options)
  // noinspection SpellCheckingInspection
  const deletedFiles = async (dir: string) => {
    await asyncPool(MAX_FILE_REQUESTS, await readdir(dir), async file => {
      if (!file.endsWith(langFileExt)) {
        return
      }

      const language = file.substring(0, file.length - langFileExt.length)
      if (!wantedLanguages.includes(language)) {
        return fs.rm(path.join(dir, file), { recursive: true, force: true })
      }
      return
    })
  }
  await Promise.all(dirs.map(deletedFiles))

  function getLocalesConfig(options: BeforeCopyExtraFilesOptions) {
    const { appOutDir, packager } = options
    if (packager.platform === Platform.MAC) {
      return { dirs: [packager.getResourcesDir(appOutDir), packager.getMacOsElectronFrameworkResourcesDir(appOutDir)], langFileExt: ".lproj" }
    }
    return { dirs: [path.join(packager.getResourcesDir(appOutDir), "..", "locales")], langFileExt: ".pak" }
  }
}

class ElectronFramework implements Framework {
  // noinspection JSUnusedGlobalSymbols
  readonly macOsDefaultTargets = ["zip", "dmg"]
  // noinspection JSUnusedGlobalSymbols
  readonly defaultAppIdPrefix = "com.electron."
  // noinspection JSUnusedGlobalSymbols
  readonly isCopyElevateHelper = true
  // noinspection JSUnusedGlobalSymbols

Review comment (suggestion):
I realize this isn't new code, but I think we could do here:
```
path.extname(file) !== langFileExt // if we remove the `.` from the extension filter
```
AND
```
const language = path.basename(file, langFileExt)
```

Code after:
      await addWinAsarIntegrity(executable, options.asarIntegrity)
    }
  } else {
    await createMacApp(packager as MacPackager, appOutDir, options.asarIntegrity, (options.platformName as ElectronPlatformName) === "mas")
  }
  await removeUnusedLanguagesIfNeeded(options)
}

async function removeUnusedLanguagesIfNeeded(options: BeforeCopyExtraFilesOptions) {
  const {
    packager: { config, platformSpecificBuildOptions },
  } = options
  const wantedLanguages = asArray(platformSpecificBuildOptions.electronLanguages || config.electronLanguages)
  if (!wantedLanguages.length) {
    return
  }

  const { dirs, langFileExt } = getLocalesConfig(options)
  // noinspection SpellCheckingInspection
  const deletedFiles = async (dir: string) => {
    await asyncPool(MAX_FILE_REQUESTS, await readdir(dir), async file => {
      if (path.extname(file) !== langFileExt) {
        return
      }

      const language = path.basename(file, langFileExt)
      if (!wantedLanguages.includes(language)) {
        return fs.rm(path.join(dir, file), { recursive: true, force: true })
      }
      return
    })
  }
  await Promise.all(dirs.map(deletedFiles))

  function getLocalesConfig(options: BeforeCopyExtraFilesOptions) {
    const { appOutDir, packager } = options
    if (packager.platform === Platform.MAC) {
      return { dirs: [packager.getResourcesDir(appOutDir), packager.getMacOsElectronFrameworkResourcesDir(appOutDir)], langFileExt: ".lproj" }
    }
    return { dirs: [path.join(packager.getResourcesDir(appOutDir), "..", "locales")], langFileExt: ".pak" }
  }
}

class ElectronFramework implements Framework {
  // noinspection JSUnusedGlobalSymbols
  readonly macOsDefaultTargets = ["zip", "dmg"]
  // noinspection JSUnusedGlobalSymbols
  readonly defaultAppIdPrefix = "com.electron."
  // noinspection JSUnusedGlobalSymbols
  readonly isCopyElevateHelper = true
  // noinspection JSUnusedGlobalSymbols