microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.48k stars 28.97k forks source link

Allow grouping of `package.nls*.json` files in a custom folder #230518

Open JairTorres1003 opened 1 week ago

JairTorres1003 commented 1 week ago

Description:

Currently, the package.nls.json and package.nls.{locale}.json files are expected to be located in the root of the project for VSCode to properly detect and apply translations. However, for projects with multiple locales, this can result in a large number of translation files cluttering the root directory.

Feature Request:

I'd like to propose a feature that allows grouping all package.nls*.json files inside a custom folder (e.g., packages-nls). The package.json would still reference these files in the usual way, but with the option to define their location, similar to how the l10n folder is currently used for bundle.l10n.json.

Example:

Instead of placing all translation files in the root, we could organize them as follows:

PROJECT_NAME
├── l10n
│   └── bundle.l10n.json
├── packages-nls
│   ├── package.nls.json
│   ├── package.nls.es.json
│   └── package.nls.de.json
├── src
│   └── extension.ts
└── package.json

And in the package.json, we could still use translation keys like this:

{
  "name": "my-extension",
  "version": "0.0.1",
  "main": "./out/extension.js",
  "l10n": "./l10n",
  "nls": "./packages-nls",
  "contributes": {
    "commands": [
      {
        "command": "my-extension.helloWorld",
        "title": "%my-extension.helloWorld.title%"
      }
    ]
  }
}

This way, developers could keep their root directory cleaner while still providing translation files.

Current Behavior:

If the package.nls*.json files are moved to a custom folder, VSCode does not recognize keys and extension shows %my-extension.helloWorld.title%

TylerLeonhardt commented 1 week ago

I want to do this, but there are two things that makes this challenging:

  1. Currently, we look for the package.nls.*.jsons in the web scenario (vscode.dev) by looking for this well known location. What you suggested would help with this... one slight modification... I think my preference would be:

    "l10n": {
      "package": "./package.nls",
      "bundle": "./l10n"
    }

    so we don't pollute the root of the manifest.

  2. The other problem I believe is that the Extension Marketplace expects package.nls.json to be next to package.json and that's another team so we'd have to coordinate that which would take time. Marketplace has a lot on their plate so I don't think this will be possible for them at the moment. cc @isidorn

JairTorres1003 commented 1 week ago

Thanks for the response, @TylerLeonhardt

I really like the grouping you suggested.

This approach keeps the structure cleaner, which I prefer, as it avoids adding more configurations at the root of the manifest. I also understand the second issue regarding the marketplace and how it might take some time, but overall, this seems like a great solution and I hope it can be implemented when possible.

Thanks for considering this improvement!