Skip to content

Commit

Permalink
string replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Dec 25, 2024
1 parent 8cee619 commit 7f6447d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"theme": "dark"
},
"publisher": "Katsute",
"version": "3.0.2",
"version": "4.0.0",
"private": true,
"engines": {
"vscode": "^1.96.0"
Expand Down Expand Up @@ -339,7 +339,6 @@
}
},
"main": "dist/index.js",
"l10n": "./l10n",
"scripts": {
"// -- dev -- //": "",
"clean": "rimraf --glob dist & rimraf --glob code-background-*.vsix",
Expand Down
2 changes: 1 addition & 1 deletion src/extension/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" |
Expand Down
33 changes: 33 additions & 0 deletions src/lib/l10n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2024 Katsute <https://github.com/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);
}

0 comments on commit 7f6447d

Please sign in to comment.