Skip to content

chore: inline i18n pt5 #1431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: jy/inline-i18n-pt4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions commands/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import * as info from './account/info';
import * as remove from './account/remove';
import * as clean from './account/clean';

const i18nKey = 'commands.account';

export const command = ['account', 'accounts'];
export const describe = i18n(`${i18nKey}.describe`);
export const describe = i18n(`commands.account.describe`);

export function builder(yargs: Argv): Argv {
addGlobalOptions(yargs);
Expand Down
20 changes: 9 additions & 11 deletions commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import {
TestingArgs,
} from '../types/Yargs';

const i18nKey = 'commands.auth';

const TRACKING_STATUS = {
STARTED: 'started',
ERROR: 'error',
Expand All @@ -61,7 +59,7 @@ const SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT =
commaSeparatedValues(ALLOWED_AUTH_METHODS);

export const command = 'auth';
export const describe = i18n(`${i18nKey}.describe`);
export const describe = i18n('commands.auth.describe');

type AuthArgs = CommonArgs &
ConfigArgs &
Expand Down Expand Up @@ -93,7 +91,7 @@ export async function handler(
}

if (!getConfigPath(configFlagValue)) {
logger.error(i18n(`${i18nKey}.errors.noConfigFileFound`));
logger.error(i18n('commands.auth.errors.noConfigFileFound'));
process.exit(EXIT_CODES.ERROR);
}

Expand Down Expand Up @@ -161,7 +159,7 @@ export async function handler(
break;
default:
logger.error(
i18n(`${i18nKey}.errors.unsupportedAuthType`, {
i18n('commands.auth.errors.unsupportedAuthType', {
supportedProtocols: SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT,
type: authType,
})
Expand Down Expand Up @@ -190,19 +188,19 @@ export async function handler(
logger.log('');
if (setAsDefault) {
logger.success(
i18n(`lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccount`, {
i18n('lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccount', {
accountName,
})
);
} else {
logger.info(
i18n(`lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault`, {
i18n('lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault', {
accountName: getConfigDefaultAccount()!,
})
);
}
logger.success(
i18n(`${i18nKey}.success.configFileUpdated`, {
i18n('commands.auth.success.configFileUpdated', {
configFilename: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
authType: successAuthMethod,
accountName,
Expand All @@ -223,7 +221,7 @@ export async function handler(
function authBuilder(yargs: Argv): Argv<AuthArgs> {
yargs.options({
'auth-type': {
describe: i18n(`${i18nKey}.options.authType.describe`),
describe: i18n('commands.auth.options.authType.describe'),
type: 'string',
choices: [
`${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
Expand All @@ -232,7 +230,7 @@ function authBuilder(yargs: Argv): Argv<AuthArgs> {
default: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
},
account: {
describe: i18n(`${i18nKey}.options.account.describe`),
describe: i18n('commands.auth.options.account.describe'),
type: 'string',
alias: 'a',
},
Expand All @@ -244,7 +242,7 @@ function authBuilder(yargs: Argv): Argv<AuthArgs> {
export const builder = makeYargsBuilder<AuthArgs>(
authBuilder,
command,
i18n(`${i18nKey}.verboseDescribe`, {
i18n('commands.auth.verboseDescribe', {
authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
configName: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
}),
Expand Down
4 changes: 1 addition & 3 deletions commands/cms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ const lighthouseScore = require('./cms/lighthouseScore');
const convertFields = require('./cms/convertFields');
const getReactModule = require('./cms/getReactModule');

const i18nKey = 'commands.cms';

exports.command = 'cms';
exports.describe = i18n(`${i18nKey}.describe`);
exports.describe = i18n(`commands.cms.describe`);

exports.builder = yargs => {
addConfigOptions(yargs);
Expand Down
6 changes: 2 additions & 4 deletions commands/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ const yargsParser = require('yargs-parser');
const { i18n } = require('../lib/lang');
const { trackCommandUsage } = require('../lib/usageTracking');

const i18nKey = 'commands.completion';

exports.command = 'completion';
exports.describe = i18n(`${i18nKey}.describe`);
exports.describe = i18n('commands.completion.describe');

exports.handler = async () => {
await trackCommandUsage('completion');
Expand All @@ -20,7 +18,7 @@ exports.builder = yargs => {
}

yargs.example([
['$0 completion >> ~/.zshrc', i18n(`${i18nKey}.examples.default`)],
['$0 completion >> ~/.zshrc', i18n('commands.completion.examples.default')],
]);
return yargs;
};
4 changes: 1 addition & 3 deletions commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ const { addConfigOptions, addGlobalOptions } = require('../lib/commonOpts');
const { i18n } = require('../lib/lang');
const set = require('./config/set');

const i18nKey = 'commands.config';

exports.command = 'config';
exports.describe = i18n(`${i18nKey}.describe`);
exports.describe = i18n('commands.config.describe');

exports.builder = yargs => {
addConfigOptions(yargs);
Expand Down
16 changes: 7 additions & 9 deletions commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ const { trackCommandUsage } = require('../lib/usageTracking');
const assets = require('./create/index');
const { i18n } = require('../lib/lang');

const i18nKey = 'commands.create';

const SUPPORTED_ASSET_TYPES = Object.keys(assets)
.filter(t => !assets[t].hidden)
.join(', ');

exports.command = 'create <type> [name] [dest]';
exports.describe = i18n(`${i18nKey}.describe`, {
exports.describe = i18n(`commands.create.describe`, {
supportedAssetTypes: SUPPORTED_ASSET_TYPES,
});

Expand All @@ -56,7 +54,7 @@ exports.handler = async options => {

if (assetType === 'global-partial') {
logger.error(
i18n(`${i18nKey}.errors.deprecatedAssetType`, {
i18n(`commands.create.errors.deprecatedAssetType`, {
assetType,
newCommand: 'hs create template',
type: 'global partial',
Expand All @@ -67,7 +65,7 @@ exports.handler = async options => {

if (!assetType || !assets[assetType]) {
logger.error(
i18n(`${i18nKey}.errors.unsupportedAssetType`, {
i18n(`commands.create.errors.unsupportedAssetType`, {
assetType,
supportedAssetTypes: SUPPORTED_ASSET_TYPES,
})
Expand All @@ -86,7 +84,7 @@ exports.handler = async options => {
await fs.ensureDir(dest);
} catch (e) {
logger.error(
i18n(`${i18nKey}.errors.unusablePath`, {
i18n(`commands.create.errors.unusablePath`, {
path: dest,
})
);
Expand All @@ -104,15 +102,15 @@ exports.handler = async options => {

exports.builder = yargs => {
yargs.positional('type', {
describe: i18n(`${i18nKey}.positionals.type.describe`),
describe: i18n(`commands.create.positionals.type.describe`),
type: 'string',
});
yargs.positional('name', {
describe: i18n(`${i18nKey}.positionals.name.describe`),
describe: i18n(`commands.create.positionals.name.describe`),
type: 'string',
});
yargs.positional('dest', {
describe: i18n(`${i18nKey}.positionals.dest.describe`),
describe: i18n(`commands.create.positionals.dest.describe`),
type: 'string',
});
yargs.option('internal', {
Expand Down
11 changes: 6 additions & 5 deletions commands/customObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { i18n } from '../lib/lang';
import { logger } from '@hubspot/local-dev-lib/logger';
import { uiBetaTag, uiLink } from '../lib/ui';

const i18nKey = 'commands.customObject';

export const command = ['custom-object', 'custom-objects', 'co'];
export const describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);
export const describe = uiBetaTag(
i18n(`commands.customObject.describe`),
false
);

function logBetaMessage() {
uiBetaTag(i18n(`${i18nKey}.betaMessage`));
uiBetaTag(i18n(`commands.customObject.betaMessage`));
logger.log(
uiLink(
i18n(`${i18nKey}.seeMoreLink`),
i18n(`commands.customObject.seeMoreLink`),
'https://developers.hubspot.com/docs/api/crm/crm-custom-objects'
)
);
Expand Down
14 changes: 7 additions & 7 deletions commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ export interface DoctorOptions {
'output-dir'?: string;
}

const i18nKey = 'commands.doctor';

export const command = 'doctor';
export const describe = i18n(`${i18nKey}.describe`);
export const describe = i18n(`commands.doctor.describe`);

export const handler = async ({
outputDir,
Expand All @@ -43,7 +41,7 @@ export const handler = async ({
if (output?.diagnosis) {
logger.log(output.diagnosis);
} else {
logger.error(i18n(`${i18nKey}.errors.generatingDiagnosis`));
logger.error(i18n(`commands.doctor.errors.generatingDiagnosis`));
return process.exit(EXIT_CODES.ERROR);
}
return process.exit(EXIT_CODES.SUCCESS);
Expand All @@ -60,10 +58,12 @@ export const handler = async ({

try {
fs.writeFileSync(outputFile, JSON.stringify(output, null, 4));
logger.success(i18n(`${i18nKey}.outputWritten`, { filename: outputFile }));
logger.success(
i18n(`commands.doctor.outputWritten`, { filename: outputFile })
);
} catch (e) {
logger.error(
i18n(`${i18nKey}.errors.unableToWriteOutputFile`, {
i18n(`commands.doctor.errors.unableToWriteOutputFile`, {
file: outputFile,
errorMessage: e instanceof Error ? e.message : e,
})
Expand All @@ -76,7 +76,7 @@ export const handler = async ({

export const builder: BuilderCallback<DoctorOptions, DoctorOptions> = yargs => {
yargs.option<keyof DoctorOptions, Options>('output-dir', {
describe: i18n(`${i18nKey}.options.outputDir`),
describe: i18n(`commands.doctor.options.outputDir`),
type: 'string',
});
addGlobalOptions(yargs);
Expand Down
44 changes: 28 additions & 16 deletions commands/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const { confirmPrompt, listPrompt } = require('../lib/prompts/promptUtils');
const { addGlobalOptions } = require('../lib/commonOpts');

const i18nKey = 'commands.project.subcommands.feedback';

const FEEDBACK_OPTIONS = {
BUG: 'bug',
GENERAL: 'general',
Expand All @@ -19,39 +17,53 @@ const FEEDBACK_URLS = {
};

exports.command = 'feedback';
exports.describe = i18n(`${i18nKey}.describe`);
exports.describe = i18n(`commands.project.subcommands.feedback.describe`);

exports.handler = async options => {
const { bug: bugFlag, general: generalFlag } = options;
const usedTypeFlag = bugFlag !== generalFlag;

await listPrompt(i18n(`${i18nKey}.feedbackType.prompt`), {
choices: Object.values(FEEDBACK_OPTIONS).map(option => ({
name: i18n(`${i18nKey}.feedbackType.${option}`),
value: option,
})),
when: !usedTypeFlag,
});
const shouldOpen = await confirmPrompt(i18n(`${i18nKey}.openPrompt`), {
when: !usedTypeFlag,
});
await listPrompt(
i18n(`commands.project.subcommands.feedback.feedbackType.prompt`),
{
choices: Object.values(FEEDBACK_OPTIONS).map(option => ({
name: i18n(
`commands.project.subcommands.feedback.feedbackType.${option}`
),
value: option,
})),
when: !usedTypeFlag,
}
);
const shouldOpen = await confirmPrompt(
i18n(`commands.project.subcommands.feedback.openPrompt`),
{
when: !usedTypeFlag,
}
);

if (shouldOpen || usedTypeFlag) {
// NOTE: for now, all feedback should go to the hubspot-cli repository
const url = FEEDBACK_URLS.BUG;
open(url, { url: true });
logger.success(i18n(`${i18nKey}.success`, { url }));
logger.success(
i18n(`commands.project.subcommands.feedback.success`, { url })
);
}
};

exports.builder = yargs => {
yargs.options({
bug: {
describe: i18n(`${i18nKey}.options.bug.describe`),
describe: i18n(
`commands.project.subcommands.feedback.options.bug.describe`
),
type: 'boolean',
},
general: {
describe: i18n(`${i18nKey}.options.general.describe`),
describe: i18n(
`commands.project.subcommands.feedback.options.general.describe`
),
type: 'boolean',
},
});
Expand Down
Loading