Skip to content

Commit 0727329

Browse files
committed
fixing(commitlint): add translation parameter to consistency prompt function
Add a translation parameter to the GEN_COMMITLINT_CONSISTENCY_PROMPT function to support localization of commit messages. This change enhances the flexibility of the commitlint integration by allowing prompts to be generated in different languages, improving usability for non-English speakers.
1 parent ebbaff0 commit 0727329

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/modules/commitlint/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const configureCommitlintIntegration = async (force = false) => {
5656
const prompts = inferPromptsFromCommitlintConfig(commitLintConfig as any);
5757

5858
const consistencyPrompts =
59-
commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts);
59+
commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts, translation);
6060

6161
// debug prompt which will generate a consistency
6262
// await fs.writeFile(

src/modules/commitlint/prompts.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import {
1212
import { getConfig } from '../../commands/config';
1313
import { i18n, I18nLocals } from '../../i18n';
1414
import { IDENTITY, INIT_DIFF_PROMPT } from '../../prompts';
15+
import { ConsistencyPrompt } from './types';
1516

1617
const config = getConfig();
17-
const translation = i18n[(config.OCO_LANGUAGE as I18nLocals) || 'en'];
1818

1919
type DeepPartial<T> = {
2020
[P in keyof T]?: {
@@ -214,7 +214,8 @@ const STRUCTURE_OF_COMMIT = config.OCO_OMIT_SCOPE
214214

215215
// Prompt to generate LLM-readable rules based on @commitlint rules.
216216
const GEN_COMMITLINT_CONSISTENCY_PROMPT = (
217-
prompts: string[]
217+
prompts: string[],
218+
translation: ConsistencyPrompt
218219
): OpenAI.Chat.Completions.ChatCompletionMessageParam[] => [
219220
{
220221
role: 'system',
@@ -233,15 +234,17 @@ Commit Message Conventions:
233234
- ${prompts.join('\n- ')}
234235
235236
JSON Output Format:
236-
- The JSON output should contain the commit messages for a bug fix and a new feature in the following format:
237+
- You MUST write all commit messages and descriptions in ${
238+
translation.localLanguage
239+
} and output them in the following JSON format. Use the exact language and writing style as shown in the example:
237240
\`\`\`json
238241
{
239-
"localLanguage": "${translation.localLanguage}",
240-
"commitFix": "<Header of commit for bug fix with scope>",
241-
"commitFeat": "<Header of commit for feature with scope>",
242-
"commitFixOmitScope": "<Header of commit for bug fix without scope>",
243-
"commitFeatOmitScope": "<Header of commit for feature without scope>",
244-
"commitDescription": "<Description of commit for both the bug fix and the feature>"
242+
"localLanguage": ${JSON.stringify(translation.localLanguage)},
243+
"commitFix": ${JSON.stringify(translation.commitFix)},
244+
"commitFeat": ${JSON.stringify(translation.commitFeat)},
245+
"commitFixOmitScope": ${JSON.stringify(translation.commitFixOmitScope)},
246+
"commitFeatOmitScope": ${JSON.stringify(translation.commitFeatOmitScope)},
247+
"commitDescription": ${JSON.stringify(translation.commitDescription)}
245248
}
246249
\`\`\`
247250
- The "commitDescription" should not include the commit message's header, only the description.

0 commit comments

Comments
 (0)