Skip to content

Instantly share code, notes, and snippets.

@sh1ch
Created April 26, 2019 00:13
Show Gist options
  • Save sh1ch/4285321e8c85008131946e37402b33dd to your computer and use it in GitHub Desktop.
Save sh1ch/4285321e8c85008131946e37402b33dd to your computer and use it in GitHub Desktop.
Visual Studio Code 拡張機能のローカライズ設定
project
|-package.json
|-package.nls.json
|-package.nls.ja.json
|-tsconfig.json
|-src
| |-extension.ts
| |-lang
| |-localization.ts
// サンプルコード部
import * as vscode from 'vscode';
import { localeText } from './lang/localization';
import { replaceText } from './core/text';
export function activate(context: vscode.ExtensionContext)
{
console.log(localeText("menu-title"));
context.subscriptions.push(disposable);
}
export function deactivate() {}
import localeEn from "../../package.nls.json";
import localeJa from "../../package.nls.ja.json";
interface ILocaleEntry
{
[key : string] : string;
}
const localeTableKey = <string>JSON.parse(<string>process.env.VSCODE_NLS_CONFIG).locale;
const localeTable = Object.assign(localeEn, ((<{[key : string] : ILocaleEntry}>
{
ja : localeJa
})[localeTableKey] || { }));
export const localeText = (key : string) : string => localeTable[key] || key;
{
...
"main": "./out/src/extension.js",
"contributes": {
// サンプル部分
"commands": [
{
"command": "extension.sample",
"title": "%menu-title%"
}
]
},
...
}
{
"menu-title": "サンプル名",
...
}
{
"menu-title": "sample name",
...
}
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment