MCPcopy
hub / github.com/SBoudrias/Inquirer.js / createLocalizedPrompts

Function createLocalizedPrompts

packages/i18n/src/create.ts:40–167  ·  view source on GitHub ↗
(locale: Locale)

Source from the content-addressed store, hash-verified

38 * @returns An object containing all prompt functions with localization applied
39 */
40export function createLocalizedPrompts(locale: Locale) {
41 return {
42 confirm(this: void, config: ConfirmConfig, context?: Context) {
43 const theme = makeTheme(config.theme, {
44 style: {
45 defaultAnswer: (text: string) => {
46 if (text === 'Y/n') return styleText('dim', `(${locale.confirm.hintYes})`);
47 if (text === 'y/N') return styleText('dim', `(${locale.confirm.hintNo})`);
48 return styleText('dim', `(${text})`);
49 },
50 },
51 });
52
53 return confirmPrompt(
54 {
55 ...config,
56 theme,
57 transformer:
58 config.transformer ??
59 ((answer: boolean) =>
60 answer ? locale.confirm.yesLabel : locale.confirm.noLabel),
61 },
62 context,
63 );
64 },
65
66 select<Value>(this: void, config: SelectConfig<Value>, context?: Context) {
67 const theme = makeTheme(config.theme, {
68 style: {
69 keysHelpTip: (keys: Array<[string, string]>) => {
70 const localizedKeys = keys.map(([key, label]): [string, string] => {
71 if (label === 'navigate') return [key, locale.select.helpNavigate];
72 if (label === 'select') return [key, locale.select.helpSelect];
73 return [key, label];
74 });
75 return localizedKeys
76 .map(([k, l]) => `${styleText('bold', k)} ${styleText('dim', l)}`)
77 .join(styleText('dim', ' • '));
78 },
79 },
80 });
81
82 return selectPrompt({ ...config, theme }, context);
83 },
84
85 checkbox<Value>(this: void, config: CheckboxConfig<Value>, context?: Context) {
86 const theme = makeTheme(config.theme, {
87 style: {
88 keysHelpTip: (keys: Array<[string, string]>) => {
89 const localizedKeys = keys.map(([key, label]): [string, string] => {
90 if (label === 'navigate') return [key, locale.checkbox.helpNavigate];
91 if (label === 'select') return [key, locale.checkbox.helpSelect];
92 if (label === 'submit') return [key, locale.checkbox.helpSubmit];
93 if (label === 'all') return [key, locale.checkbox.helpAll];
94 if (label === 'invert') return [key, locale.checkbox.helpInvert];
95 return [key, label];
96 });
97 return localizedKeys

Callers 5

zh.tsFile · 0.90
fr.tsFile · 0.90
es.tsFile · 0.90
pt.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected