diff --git a/package-lock.json b/package-lock.json index eb9c5486..d3355fbc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "code-background", - "version": "3.0.2", + "version": "4.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "code-background", - "version": "3.0.2", + "version": "4.0.0", "license": "GPL-2.0-only", "devDependencies": { "@types/node": "22.10.1", diff --git a/package.json b/package.json index 29ee31cb..4218ef22 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "theme": "dark" }, "publisher": "Katsute", - "version": "3.0.2", + "version": "4.0.0", "private": true, "engines": { "vscode": "^1.96.0" @@ -339,7 +339,6 @@ } }, "main": "dist/index.js", - "l10n": "./l10n", "scripts": { "// -- dev -- //": "", "clean": "rimraf --glob dist & rimraf --glob code-background-*.vsix", diff --git a/src/extension/package.ts b/src/extension/package.ts index 23f940c8..b35c0561 100644 --- a/src/extension/package.ts +++ b/src/extension/package.ts @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -export const pkg = require("../../package.json"); // do not convert to import +export const pkg = Object.freeze(require("../../package.json")); // do not convert to import export type ConfigurationKey = "windowBackgrounds" | diff --git a/src/lib/l10n.ts b/src/lib/l10n.ts new file mode 100644 index 00000000..0aa1e30a --- /dev/null +++ b/src/lib/l10n.ts @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Katsute + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +import { env } from "vscode"; + +type LocaleSet = {[key: string]: string}; + +// https://code.visualstudio.com/docs/getstarted/locales +const Locales: {[key: string]: LocaleSet} = Object.freeze({ + "en": Object.freeze(require("../../package.nls.json")) +}); + +const getString: () => LocaleSet = () => Locales[env.language] ?? {}; + +export const format: (key: string, ...args: any[]) => string = (key: string, ...args: any[]): string => { + const str: string = getString()[key] ?? getString()["en"] ?? key; + return str.replace(/{(\d+)}/g, (m, i) => args[i] ?? m); +} \ No newline at end of file