VSCode Extension Internationalization Support

A comprehensive guide on implementing internationalization in VSCode extensions, covering both menu and extension content localization.

Mar 14, 2025 · 2 min read · 214 Words · -Views -Comments · Programming
VSC Extension I18n 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

Recently, I needed to implement internationalization for my VSCode extension. Since the official documentation on this topic was sparse, with only an example provided, I’ll summarize how to implement internationalization here.

Internationalization can be divided into two categories: menu internationalization and extension content internationalization, such as prompt messages.

Configure package.json

 "contributes": {
    "commands": [
 {
        "command": "gitlink.openInGitHub",
        "title": "%command.openInGitHub.title%"
 }
 ]
 }

Note that the title uses a key format, and the key needs to be wrapped with %.

Internationalization JSON Files in Project Root

Below are two language files, default English and Simplified Chinese. If other languages are needed, corresponding JSON files can be added.

  • package.nls.json
  • package.nls.zh-cn.json

The content format is as follows:

{
  "command.openInGitHub.title": "Open in GitHub"
}

Extension Content Internationalization

Create l10n Folder

Create an l10n folder in the project root directory.

Configure package.json

{
  "l10n": "./l10n",
}

Execute Resource Extraction Command

Execute the following command to extract all strings from the src directory to form internationalization JSON files.

npx @vscode/l10n-dev export --outDir ./l10n ./src

Note that files need to use the following format to be correctly extracted.

vscode.l10n.t('Congratulations, your extension "GitLink" is now active!')

Create Target Language JSON Files

https://static.1991421.cn/2025/2025-03-14-161959.jpeg

Test

With the internationalization configuration complete, try changing VSCode’s language settings to experience different languages during operation.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover