Regarding the question on localizing VSCode extensions, I am also curious why the localize function requires two parameters.
When it comes to localizing settings, it's a simple process of replacing literal values with tokens surrounded by percent signs, which are then replaced using a dictionary from a file based on the current locale.
However, the localize
function demands at least two parameters - a key
and a message
. It can also accept an unspecified number of subsequent parameters of any type, referred to as "args."
The lack of documentation on this topic is quite noticeable.
Initially, the sample code won't even compile until you update the package.json
to require a minimum vscode version of 1.34 instead of 1.32 in order to accommodate updates to the TS typing files. Once this modification is made, the sample compiles and launches, but does not appear to work as expected (the activate function does not run; I am still investigating this issue).
The sample includes a call to localize with the key "sayHello.text," but I couldn't find a corresponding string in the localization resources. The use of arbitrary args
suggests dynamic composition at runtime, although this is not demonstrated in the sample code. Due to the lack of documentation, it's difficult to understand the functionality fully.
Can anyone provide insight into the parameters?
After examining the vscode-nls repository, I came across the following code snippet.
export function localize(_key: string | LocalizeInfo, message: string, ...args: any[]): string {
return format(message, args);
}
Despite the appearance that it does not utilize _key
, there is a localizeFunc
with a similar signature that does make use of it. I suspect a configuration function call may be manipulating names behind the scenes.