import { Args, Awaitable, Command, CommandContext, DefaultGunshiParams, ExtendContext, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, PluginWithExtension, Prettify } from "@gunshi/plugin"; //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/resolver.d.ts //#region src/resolver.d.ts /** * An argument schema definition for command-line argument parsing. * * This schema is similar to the schema of Node.js `util.parseArgs` but with extended features: * - Additional `required`, `description`, and `hidden` properties * - Extended `type` support: 'string', 'boolean', 'number', 'enum', 'positional', 'custom' * - Simplified `default` property (single type, not union types) * * @example * Basic string argument: * ```ts * const schema: ArgSchema = { * type: 'string', * description: 'Server hostname', * default: 'localhost' * } * ``` * * @example * Required number argument with alias: * ```ts * const schema: ArgSchema = { * type: 'number', * short: 'p', * description: 'Port number to listen on', * required: true * } * ``` * * @example * Enum argument with choices: * ```ts * const schema: ArgSchema = { * type: 'enum', * choices: ['info', 'warn', 'error'], * description: 'Logging level', * default: 'info' * } * ``` */ interface ArgSchema { /** * Type of the argument value. * * - `'string'`: Text value (default if not specified) * - `'boolean'`: `true`/`false` flag (can be negatable with `--no-` prefix) * - `'number'`: Numeric value (parsed as integer or float) * - `'enum'`: One of predefined string values (requires `choices` property) * - `'positional'`: Non-option argument by position * - `'custom'`: Custom parsing with user-defined `parse` function * * @example * Different argument types: * ```ts * { * name: { type: 'string' }, // --name value * verbose: { type: 'boolean' }, // --verbose or --no-verbose * port: { type: 'number' }, // --port 3000 * level: { type: 'enum', choices: ['debug', 'info'] }, * file: { type: 'positional' }, // first positional arg * config: { type: 'custom', parse: JSON.parse } * } * ``` */ type: 'string' | 'boolean' | 'number' | 'enum' | 'positional' | 'custom'; /** * Single character alias for the long option name. * * As example, allows users to use `-x` instead of `--extended-option`. * Only valid for non-positional argument types. * * @example * Short alias usage: * ```ts * { * verbose: { * type: 'boolean', * short: 'v' // Enables both --verbose and -v * }, * port: { * type: 'number', * short: 'p' // Enables both --port 3000 and -p 3000 * } * } * ``` */ short?: string; /** * Human-readable description of the argument's purpose. * * Used for help text generation and documentation. * Should be concise but descriptive enough to understand the argument's role. * * @example * Descriptive help text: * ```ts * { * config: { * type: 'string', * description: 'Path to configuration file' * }, * timeout: { * type: 'number', * description: 'Request timeout in milliseconds' * } * } * ``` */ description?: string; /** * Hide the argument from generated help or usage output. * * This is metadata for renderers. It does not affect parsing, validation, * required checks, defaults, conflicts, or resolved values. * * @example * Hidden compatibility option: * ```ts * { * legacy: { * type: 'string', * hidden: true, * description: 'Deprecated compatibility option' * } * } * ``` */ hidden?: boolean; /** * Marks the argument as required. * * When `true`, the argument must be provided by the user. * If missing, an `ArgResolveError` with type 'required' will be thrown. * * For single-value positional arguments, omitting `required` keeps the argument * required for compatibility. Set `required: false` to make a positional argument * optional. Optional positional arguments leave enough input values for later * required positional arguments before consuming a value. * * @example * Required arguments: * ```ts * { * input: { * type: 'string', * required: true, // Must be provided: --input file.txt * description: 'Input file path' * }, * source: { * type: 'positional', * required: true // First positional argument must exist * } * } * ``` */ required?: boolean; /** * Allows the argument to accept multiple values. * * When `true`, the resolved value becomes an array. * For options: can be specified multiple times (--tag foo --tag bar) * For positional: collects remaining positional arguments after preserving values for * later required positional arguments. * * Note: Only `true` is allowed (not `false`) to make intent explicit. * * @example * Multiple values: * ```ts * { * tags: { * type: 'string', * multiple: true, // --tags foo --tags bar → ['foo', 'bar'] * description: 'Tags to apply' * }, * files: { * type: 'positional', * multiple: true // Collects all remaining positional args * } * } * ``` */ multiple?: true; /** * Enables negation for boolean arguments using `--no-` prefix. * * When `true`, allows users to explicitly set the boolean to `false` * using `--no-option-name`. When `false` or omitted, only positive * form is available. * * Only applicable to `type: 'boolean'` arguments. * * @example * Negatable boolean: * ```ts * { * color: { * type: 'boolean', * negatable: true, * default: true, * description: 'Enable colorized output' * } * // Usage: --color (true), --no-color (false) * } * ``` */ negatable?: boolean; /** * Array of allowed string values for enum-type arguments. * * Required when `type: 'enum'`. The argument value must be one of these choices, * otherwise an `ArgResolveError` with type 'type' will be thrown. * * Supports both mutable arrays and readonly arrays for type safety. * * @example * Enum choices: * ```ts * { * logLevel: { * type: 'enum', * choices: ['debug', 'info', 'warn', 'error'] as const, * default: 'info', * description: 'Logging verbosity level' * }, * format: { * type: 'enum', * choices: ['json', 'yaml', 'toml'], * description: 'Output format' * } * } * ``` */ choices?: string[] | readonly string[]; /** * Default value used when the argument is not provided. * * The type must match the argument's `type` property: * - `string` type: string default * - `boolean` type: boolean default * - `number` type: number default * - `enum` type: must be one of the `choices` values * - `positional`/`custom` type: string, boolean, or number default * * For single-value positional arguments, the default is used when the positional * value is missing or when the value is preserved for later required positional * arguments, unless `required: true` is set. * * @example * Default values by type: * ```ts * { * host: { * type: 'string', * default: 'localhost' // string default * }, * verbose: { * type: 'boolean', * default: false // boolean default * }, * port: { * type: 'number', * default: 8080 // number default * }, * level: { * type: 'enum', * choices: ['low', 'high'], * default: 'low' // must be in choices * } * } * ``` */ default?: string | boolean | number; /** * Converts the argument name from camelCase to kebab-case for CLI usage. * * When `true`, a property like `maxCount` becomes available as `--max-count`. * This allows [CAC](https://github.com/cacjs/cac) user-friendly property names while maintaining CLI conventions. * * Can be overridden globally with `resolveArgs({ toKebab: true })`. * * Note: Only `true` is allowed (not `false`) to make intent explicit. * * @example * Kebab-case conversion: * ```ts * { * maxRetries: { * type: 'number', * toKebab: true, // Accessible as --max-retries * description: 'Maximum retry attempts' * }, * enableLogging: { * type: 'boolean', * toKebab: true // Accessible as --enable-logging * } * } * ``` */ toKebab?: true; /** * Names of other options that conflict with this option. * * When this option is used together with any of the conflicting options, * an `ArgResolveError` with type 'conflict' will be thrown. * * Conflicts only need to be defined on one side - if option A defines a conflict * with option B, the conflict is automatically detected when both are used, * regardless of whether B also defines a conflict with A. * * Supports both single option name or array of option names. * Option names must match the property keys in the schema object exactly * (no automatic conversion between camelCase and kebab-case). * * @example * Single conflict (bidirectional definition): * ```ts * { * summer: { * type: 'boolean', * conflicts: 'autumn' // Cannot use --summer with --autumn * }, * autumn: { * type: 'boolean', * conflicts: 'summer' // Can define on both sides for clarity * } * } * ``` * * @example * Single conflict (one-way definition): * ```ts * { * summer: { * type: 'boolean', * conflicts: 'autumn' // Only defined on summer side * }, * autumn: { * type: 'boolean' * // No conflicts defined, but still cannot use with --summer * } * } * // Usage: --summer --autumn will throw error * // Error: "Optional argument '--summer' conflicts with '--autumn'" * ``` * * @example * Multiple conflicts: * ```ts * { * port: { * type: 'number', * conflicts: ['socket', 'pipe'], // Cannot use with --socket or --pipe * description: 'TCP port number' * }, * socket: { * type: 'string', * conflicts: ['port', 'pipe'], // Cannot use with --port or --pipe * description: 'Unix socket path' * }, * pipe: { * type: 'string', * conflicts: ['port', 'socket'], // Cannot use with --port or --socket * description: 'Named pipe path' * } * } * // These three options are mutually exclusive * ``` * * @example * With kebab-case conversion: * ```ts * { * summerSeason: { * type: 'boolean', * toKebab: true, // Accessible as --summer-season * conflicts: 'autumnSeason' // Must use property key, not CLI name * }, * autumnSeason: { * type: 'boolean', * toKebab: true // Accessible as --autumn-season * } * } * // Error: "Optional argument '--summer-season' conflicts with '--autumn-season'" * ``` */ conflicts?: string | string[]; /** * Display name hint for help text generation. * * Provides a meaningful type hint for the argument value in help output. * Particularly useful for `type: 'custom'` arguments where the type * name would otherwise be unhelpful. * * @example * Metavar usage: * ```ts * { * port: { * type: 'custom', * parse: (v: string) => parseInt(v, 10), * metavar: 'integer', * description: 'Port number (1-65535)' * } * } * // Help output: --port Port number (1-65535) * ``` */ metavar?: string; /** * Custom parsing function for `type: 'custom'` arguments. * * Required when `type: 'custom'`. Receives the raw string value and must * return the parsed result. Should throw an Error (or subclass) if parsing fails. * * The function's return type becomes the resolved argument type. * * @param value - Raw string value from command line * @returns Parsed value of any type * @throws {Error} Error or subclass when value is invalid * * @example * Custom parsing functions: * ```ts * { * config: { * type: 'custom', * parse: (value: string) => { * try { * return JSON.parse(value) // Parse JSON config * } catch { * throw new Error('Invalid JSON configuration') * } * }, * description: 'JSON configuration object' * }, * date: { * type: 'custom', * parse: (value: string) => { * const date = new Date(value) * if (isNaN(date.getTime())) { * throw new Error('Invalid date format') * } * return date * } * } * } * ``` */ parse?: (value: string) => any; } /** * An object that contains {@link ArgSchema | argument schema}. * * This type is used to define the structure and validation rules for command line arguments. */ interface Args$1 { [option: string]: ArgSchema; } //#endregion //#region ../gunshi/src/types.d.ts /** * Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}. * * @since v0.27.0 */ type ExtendContext$1 = Record; /** * Gunshi unified parameter type. * * This type combines both argument definitions and command context extensions. * * @typeParam P - The type of parameters, which can include `args` and `extensions`. * * @since v0.27.0 */ interface GunshiParams$1

{ /** * Command argument definitions. */ args: P extends { args: infer A extends Args$1; } ? A : Args$1; /** * Command context extensions. */ extensions: P extends { extensions: infer E extends ExtendContext$1; } ? E : {}; } /** * Default Gunshi parameters. * * @since v0.27.0 */ type DefaultGunshiParams$1 = GunshiParams$1; //#endregion //#region ../shared/src/constants.d.ts /** * @author kazuya kawaguchi (a.k.a. kazupon) * @license MIT */ declare const BUILT_IN_PREFIX = "_"; declare const PLUGIN_PREFIX = "g"; declare const ARG_PREFIX = "arg"; declare const BUILT_IN_KEY_SEPARATOR = ":"; type CommonArgType = { readonly help: { readonly type: 'boolean'; readonly short: 'h'; readonly description: string; }; readonly version: { readonly type: 'boolean'; readonly short: 'v'; readonly description: string; }; }; declare const COMMON_ARGS: CommonArgType; declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "ARGUMENTS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE", "DEFAULT", "CHOICES"]; declare const ARG_ERROR_RESOURCE_KEYS: readonly ["err:arg:required-option", "err:arg:required-positional", "err:arg:invalid-type", "err:arg:invalid-choice", "err:arg:custom-parse", "err:arg:unknown-option"]; declare const COMMAND_ERROR_RESOURCE_KEYS: readonly ["err:cmd:not-found"]; declare const SUGGESTION_ERROR_RESOURCE_KEYS: readonly ["err:suggestion:did-you-mean"]; //#endregion //#region ../gunshi/src/index.d.ts //#endregion //#region ../shared/src/types.d.ts type RemoveIndexSignature = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] }; /** * Make all properties in T deeply writeable (not readonly) */ /** * Remove index signature from object or record type. */ type RemovedIndex = RemoveIndexSignature<{ [K in keyof T]: T[K] }>; /** * Resolve a key on {@link Args}. */ type KeyOfArgs = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract}` : never : never }[keyof A]; /** * Generate a namespaced key. */ type GenerateNamespacedKey = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`; /** * Command i18n built-in arguments keys. */ type CommandBuiltinArgsKeys = keyof typeof COMMON_ARGS; /** * Command i18n built-in resource keys. */ type CommandBuiltinResourceKeys = (typeof COMMAND_BUILTIN_RESOURCE_KEYS)[number]; /** * Args validation error resource keys. */ type ArgErrorResourceKeys = (typeof ARG_ERROR_RESOURCE_KEYS)[number]; /** * Command validation error resource keys. */ type CommandErrorResourceKeys = (typeof COMMAND_ERROR_RESOURCE_KEYS)[number]; /** * Suggestion error resource keys. */ type SuggestionErrorResourceKeys = (typeof SUGGESTION_ERROR_RESOURCE_KEYS)[number]; /** * Error resource keys. */ type ErrorResourceKeys = ArgErrorResourceKeys | CommandErrorResourceKeys | SuggestionErrorResourceKeys; /** * Built-in resource keys. */ type BuiltinResourceKeys = ErrorResourceKeys | CommandBuiltinArgsKeys | CommandBuiltinResourceKeys; /** * Built-in resource. */ type BuiltinResource = Partial>; /** * Command built-in keys. */ type CommandBuiltinKeys = GenerateNamespacedKey; /** * Command i18n option keys. * The command i18n option keys are used by the i18n plugin for translation. */ type CommandArgKeys>, string>, typeof ARG_PREFIX>> = C extends { name: infer N; } ? (N extends string ? GenerateNamespacedKey : K) : K; /** * Resolve translation keys for command context. */ type ResolveTranslationKeys = {}, // for extended resources R extends string = keyof RemovedIndex, T extends string = (C extends { name: infer N; } ? N extends string ? GenerateNamespacedKey : R : R | CommandBuiltinKeys), O = CommandArgKeys> = ErrorResourceKeys | CommandBuiltinKeys | O | T; //#endregion //#region ../shared/src/localization.d.ts //#endregion //#region ../shared/src/utils.d.ts /** * Resolve a namespaced key for built-in resources. * * Built-in keys are prefixed with "_:". * * @typeParam K - The type of the built-in key to resolve. Defaults to command built-in argument and resource keys. * * @param key - The built-in key to resolve. * @returns Prefixed built-in key. */ declare function resolveBuiltInKey(key: K): GenerateNamespacedKey; /** * Resolve a namespaced key for argument resources. * * Argument keys are prefixed with "arg:". * If the command name is provided, it will be prefixed with the command name (e.g. "cmd1:arg:foo"). * * @typeParam A - The {@linkcode Args} type extracted from G * * @param key - The argument key to resolve. * @param name - The command name. * @returns Prefixed argument key. */ declare function resolveArgKey>>(key: K, name?: string): string; /** * Resolve a namespaced key for non-built-in resources. * * Non-built-in keys are not prefixed with any special characters. If the command name is provided, it will be prefixed with the command name (e.g. "cmd1:foo"). * * @typeParam T - The type of the non-built-in key to resolve. Defaults to string. * * @param key - The non-built-in key to resolve. * @param name - The command name. * @returns Prefixed non-built-in key. */ declare function resolveKey = {}, K extends string = (keyof T extends string ? keyof T : string)>(key: K, name?: string): string; //#endregion //#region ../shared/src/index.d.ts //#endregion //#region src/types.d.ts /** * The unique identifier for the i18n plugin. */ declare const pluginId: GenerateNamespacedKey<'i18n', typeof PLUGIN_PREFIX>; /** * Type representing the unique identifier for i18n plugin. */ type PluginId = typeof pluginId; /** * Extended command context which provides utilities via i18n plugin. * These utilities are available via `CommandContext.extensions['g:i18n']`. * * @typeParam G - Type parameter extending {@linkcode GunshiParams} */ interface I18nExtension = DefaultGunshiParams> { /** * Command locale */ locale: Intl.Locale; /** * Translate a message. * * @typeParam A - The {@linkcode Args} type extracted from G * @typeParam C - The command context type (usually `{}`) * @typeParam E - The extended resource keys type (usually `{}`) * * @param key - Translation key * @param values - Values to interpolate * @returns Translated message. If the key is not found: * - For custom keys: returns an empty string ('') * - For built-in keys (prefixed with '_:'): returns the key itself */ translate: = {}, // for extended resources K = ResolveTranslationKeys>(key: K, values?: Record) => string; /** * Load command resources. * * @param locale - A locale to load resources for * @param ctx - A {@linkcode CommandContext | command context} * @param command - A {@linkcode Command | command} to load resources for * @returns Whether the resources were loaded successfully */ loadResource: (locale: string | Intl.Locale, ctx: CommandContext, command: Command) => Promise; /** * Register global option resources. * * @param option - An option name * @param resources - A map of resources for different locales */ registerGlobalOptionResources: (option: string, resources: Record) => void; } /** * i18n plugin options */ interface I18nPluginOptions { /** * Locale to use for translations */ locale?: string | Intl.Locale; /** * Translation adapter factory */ translationAdapterFactory?: TranslationAdapterFactory; /** * Built-in localizable resources */ builtinResources?: Record; } /** * Translation adapter factory. */ type TranslationAdapterFactory = (options: TranslationAdapterFactoryOptions) => TranslationAdapter; /** * Translation adapter factory options. */ interface TranslationAdapterFactoryOptions { /** * A locale (BCP 47 language tag). */ locale: string; /** * A fallback locale. * * @default DEFAULT_LOCALE ('en-US') */ fallbackLocale: string; } /** * Translation adapter. * * This adapter is used to custom message formatter like {@link https://github.com/intlify/vue-i18n/blob/master/spec/syntax.ebnf | Intlify message format}, {@link https://github.com/tc39/proposal-intl-messageformat | `Intl.MessageFormat` (MF2)}, and etc. * This adapter will support localization with your preferred message format. */ interface TranslationAdapter { /** * Get a resource of locale. * * @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47) * @returns A resource of locale. if resource not found, return `undefined`. */ getResource(locale: string): Record | undefined; /** * Set a resource of locale. * * @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47) * @param resource - A resource of locale */ setResource(locale: string, resource: Record): void; /** * Get a message of locale. * * @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47) * @param key - A key of message resource * @returns A message of locale. if message not found, return `undefined`. */ getMessage(locale: string, key: string): MessageResource | undefined; /** * Translate a message. * * @param locale - A Locale at the time of command execution. That is Unicord locale ID (BCP 47) * @param key - A key of message resource * @param values - A values to be resolved in the message * @returns A translated message, if message is not translated, return `undefined`. */ translate(locale: string, key: string, values?: Record): string | undefined; } /** * Command resource type for i18n plugin. * * @typeParam G - Type parameter extending {@linkcode GunshiParams} */ type CommandResource = { /** * Command description. */ description: string; } & { [Arg in GenerateNamespacedKey>>, typeof ARG_PREFIX>]?: string } & { [key: string]: string; }; /** * Command resource fetcher. * * @typeParam G - Type parameter extending {@linkcode GunshiParams} * * @param locale - A {@link Intl.Locale | locale} at the time of command execution. * @returns A fetched {@link CommandResource | command resource}. */ type CommandResourceFetcher = (locale: Intl.Locale) => Awaitable>; /** * I18n-aware command interface that extends the base Command with resource support * * @typeParam G - Type parameter extending {@linkcode GunshiParams} */ interface I18nCommand extends Command { /** * Command resource fetcher for i18n support. * This property is specific to i18n-enabled commands. */ resource?: CommandResourceFetcher; } //#endregion //#region src/helpers.d.ts /** * The result type of the {@linkcode defineI18n} function * * @internal */ type I18nCommandDefinitionResult = Prettify & ('resource' extends keyof C ? { resource: CommandResourceFetcher; } : { resource?: CommandResourceFetcher | undefined; }) & { [K in Exclude, keyof C | 'resource'>]?: I18nCommand[K] }>; /** * The result type of the {@linkcode withI18nResource} function * * @internal */ type WithI18nResourceResult = Command> = Prettify; } & { [K in Exclude, keyof C | 'resource'>]?: I18nCommand[K] }>; /** * Define an i18n-aware {@link I18nCommand | command}. * * The difference from the {@linkcode define} function is that you can define a `resource` option that can load a locale. * * @example * ```ts * import { defineI18n } from '@gunshi/plugin-i18n' * * const greetCommand = defineI18n({ * name: 'greet', * args: { * name: { type: 'string', description: 'Name to greet' } * }, * resource: locale => { * switch (locale.toString()) { * case 'ja-JP': { * return { * 'description': '誰かにあいさつ', * 'arg:name': 'あいさつするための名前' * } * } * // other locales ... * } * }, * run: ctx => { * console.log(`Hello, ${ctx.values.name}!`) * } * }) * ``` * * @typeParam G - A {@linkcode GunshiParamsConstraint} type * @typeParam A - An {@linkcode Args} type extracted from {@linkcode GunshiParamsConstraint} * @typeParam C - The inferred command type * * @param definition - A {@link I18nCommand | command} definition with i18n support * @returns A defined {@link I18nCommand | command} with compatible {@linkcode Command} type */ declare function defineI18n, C = {}>(definition: C & { args?: A; } & Omit; }>, 'resource' | 'args'> & { resource?: CommandResourceFetcher<{ args: A; extensions: ExtractExtensions; }>; }): I18nCommandDefinitionResult<{ args: A; extensions: ExtractExtensions; }, C>; /** * Return type for {@link defineI18nWithTypes} * * @typeParam DefaultExtensions - The {@linkcode ExtendContext} type extracted from G * @typeParam DefaultArgs - The {@linkcode Args} type extracted from G * * @internal */ type DefineI18nWithTypesReturn = (definition: C & { args?: A; } & Omit, 'resource' | 'args'> & { resource?: CommandResourceFetcher<{ args: A; extensions: DefaultExtensions; }>; }) => I18nCommandDefinitionResult<{ args: A; extensions: DefaultExtensions; }, C>; /** * Define an i18n-aware {@link I18nCommand | command} with types * * This helper function allows specifying the type parameter of {@linkcode GunshiParams} * while inferring the {@linkcode Args} type, {@linkcode ExtendContext} type from the definition. * * @example * ```ts * import { defineI18nWithTypes } from '@gunshi/plugin-i18n' * * // Define a command with specific extensions type * type MyExtensions = { logger: { log: (message: string) => void } } * * const greetCommand = defineI18nWithTypes<{ extensions: MyExtensions }>()({ * name: 'greet', * args: { * name: { type: 'string', description: 'Name to greet' } * }, * resource: locale => { * switch (locale.toString()) { * case 'ja-JP': { * return { * 'description': '誰かにあいさつ', * 'arg:name': 'あいさつするための名前' * } * } * // other locales ... * } * }, * run: ctx => { * // ctx.values is inferred as { name?: string } * // ctx.extensions is MyExtensions * } * }) * ``` * * @typeParam G - A {@linkcode GunshiParams} type * * @returns A function that takes a command definition via {@linkcode defineI18n} */ declare function defineI18nWithTypes(): DefineI18nWithTypesReturn, ExtractArgs>; /** * Add i18n resource to an existing command * * @example * ```ts * import { define } from 'gunshi' * import { withI18nResource } from '@gunshi/plugin-i18n' * * const myCommand = define({ * name: 'myCommand', * args: { * input: { type: 'string', description: 'Input value' } * }, * run: ctx => { * console.log(`Input: ${ctx.values.input}`) * } * }) * * const i18nCommand = withI18nResource(basicCommand, async locale => { * const resource = await import( * `./path/to/resources/test/${locale.toString()}.json`, * { with: { type: 'json' } } * ).then(l => l.default || l) * return resource * }) * ``` * * @param command - A defined {@link Command | command} with {@linkcode define} function * @param resource - A {@link CommandResourceFetcher | resource fetcher} for the command * @returns A {@link I18nCommand | command} with i18n resource support */ declare function withI18nResource>(command: C, resource: CommandResourceFetcher): WithI18nResourceResult; //#endregion //#region src/translation.d.ts /** * Create a translation adapter. * * @param options - Options for the translation adapter, see {@linkcode TranslationAdapterFactoryOptions} * @returns A translation adapter instance */ declare function createTranslationAdapter(options: TranslationAdapterFactoryOptions): TranslationAdapter; /** * Default implementation of {@linkcode TranslationAdapter}. */ declare class DefaultTranslation implements TranslationAdapter { #private; /** * Creates a new instance of DefaultTranslation. * * @param options - Options for the translation adapter, see {@linkcode TranslationAdapterFactoryOptions} */ constructor(options: TranslationAdapterFactoryOptions); /** * Get a resource of locale. * * @param locale - A locale of resource (BCP 47 language tag) * @returns A resource of locale. If resource not found, return `undefined`. */ getResource(locale: string): Record | undefined; /** * Set a resource of locale. * * @param locale - A locale of resource (BCP 47 language tag) * @param resource - A resource of locale */ setResource(locale: string, resource: Record): void; /** * Get a message of locale. * * @param locale - A locale of message (BCP 47 language tag) * @param key - A key of message resource * @returns A message of locale. If message not found, return `undefined`. */ getMessage(locale: string, key: string): string | undefined; /** * Translate a message. * * @param locale - A locale of message (BCP 47 language tag) * @param key - A key of message resource * @param values - A values to interpolate in the message * @returns A translated message, if message is not translated, return `undefined`. */ translate(locale: string, key: string, values?: Record): string | undefined; } //#endregion //#region src/index.d.ts /** * The default locale string, which format is BCP 47 language tag. */ declare const DEFAULT_LOCALE = "en-US"; /** * i18n plugin * * @param options - An {@linkcode I18nPluginOptions | I18n plugin options} * @returns A defined plugin as i18n */ declare function i18n(options?: I18nPluginOptions): PluginWithExtension>; //#endregion export { CommandResource, CommandResourceFetcher, DEFAULT_LOCALE, DefaultTranslation, I18nCommand, I18nExtension, I18nPluginOptions, PluginId, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, createTranslationAdapter, i18n as default, defineI18n, defineI18nWithTypes, pluginId, resolveArgKey, resolveBuiltInKey, resolveKey, withI18nResource };