@vscode/l10n
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -60,2 +60,12 @@ // src/browser/reader.ts | ||
formatArgs = !args || typeof args[0] !== "object" ? args : args[0]; | ||
} else if (firstArg instanceof Array) { | ||
const replacements = args.slice(1); | ||
if (firstArg.length !== replacements.length + 1) { | ||
throw new Error("expected a string as the first argument to l10n.t"); | ||
} | ||
let str = firstArg[0]; | ||
for (let i = 1; i < firstArg.length; i++) { | ||
str += `{${i - 1}}` + firstArg[i]; | ||
} | ||
return t(str, ...replacements); | ||
} else { | ||
@@ -69,6 +79,3 @@ message = firstArg.message; | ||
} | ||
if (!bundle) { | ||
return format(message, formatArgs); | ||
} | ||
const messageFromBundle = bundle[key]; | ||
const messageFromBundle = bundle?.[key]; | ||
if (!messageFromBundle) { | ||
@@ -75,0 +82,0 @@ return format(message, formatArgs); |
@@ -56,2 +56,8 @@ /** | ||
* @public | ||
* Type that can be used as replacements in `l10n.t()` calls. | ||
*/ | ||
export declare type L10nReplacement = string | number | boolean; | ||
/** | ||
* @public | ||
* Marks a string for localization. If the bundle has a localized value for this message, then that localized | ||
@@ -66,3 +72,3 @@ * value will be returned (with injected `args` values for any templated values). | ||
*/ | ||
export declare function t(message: string, ...args: Array<string | number | boolean>): string; | ||
export declare function t(message: string, ...args: Array<L10nReplacement>): string; | ||
@@ -80,6 +86,22 @@ /** | ||
*/ | ||
export declare function t(message: string, args: Record<string, any>): string; | ||
export declare function t(message: string, args: Record<string, L10nReplacement>): string; | ||
/** | ||
* @public | ||
* Marks a string for localization. This function signature is made for usage | ||
* with tagged template literals. | ||
* | ||
* The more verbose overload should still be used if comments are required. | ||
* @example | ||
* ``` | ||
* l10n.t`Hello ${name}!` | ||
* ``` | ||
* @param message - String message components | ||
* @param args - Replacement components in the string | ||
* @returns localized string with injected arguments. | ||
*/ | ||
export declare function t(strs: TemplateStringsArray, ...replacements: L10nReplacement[]): string; | ||
/** | ||
* @public | ||
* Marks a string for localization. If the bundle has a localized value for this message, then that localized | ||
@@ -86,0 +108,0 @@ * value will be returned (with injected args values for any templated values). |
@@ -902,2 +902,12 @@ "use strict"; | ||
formatArgs = !args || typeof args[0] !== "object" ? args : args[0]; | ||
} else if (firstArg instanceof Array) { | ||
const replacements = args.slice(1); | ||
if (firstArg.length !== replacements.length + 1) { | ||
throw new Error("expected a string as the first argument to l10n.t"); | ||
} | ||
let str = firstArg[0]; | ||
for (let i = 1; i < firstArg.length; i++) { | ||
str += `{${i - 1}}` + firstArg[i]; | ||
} | ||
return t(str, ...replacements); | ||
} else { | ||
@@ -911,6 +921,3 @@ message = firstArg.message; | ||
} | ||
if (!bundle) { | ||
return format(message, formatArgs); | ||
} | ||
const messageFromBundle = bundle[key]; | ||
const messageFromBundle = bundle?.[key]; | ||
if (!messageFromBundle) { | ||
@@ -917,0 +924,0 @@ return format(message, formatArgs); |
{ | ||
"name": "@vscode/l10n", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "A helper library to assist in localizing subprocesses spun up by VS Code extensions", | ||
@@ -5,0 +5,0 @@ "author": "Microsoft Corporation", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57149
1181