Skip to content

Commit

Permalink
Leverage the vscode-nls types for the filler
Browse files Browse the repository at this point in the history
We need to stub the values, not the types.
  • Loading branch information
remcohaszing committed May 10, 2024
1 parent ad261cc commit 8570a4d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions fillers/vscode-nls.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
interface LocalizeInfo {
key: string
comment: string[]
}
type LocalizeFunc = (info: LocalizeInfo | string, message: string, ...args: string[]) => string
type LoadFunc = (file?: string) => LocalizeFunc
import { type LoadFunc, type LocalizeFunc } from 'vscode-nls'

function format(message: string, args: string[]): string {
return args.length === 0
const localize: LocalizeFunc = (key, message, ...args) =>
args.length === 0
? message
: message.replace(/{(\d+)}/g, (match, [index]: number[]) =>
index in args ? args[index] : match
)
}

const localize: LocalizeFunc = (key, message, ...args) => format(message, args)
: message.replace(/{(\d+)}/g, (match, [index]) => (index in args ? String(args[index]) : match))

export function loadMessageBundle(): LocalizeFunc {
return localize
Expand Down

0 comments on commit 8570a4d

Please sign in to comment.