Skip to content

Commit 4320ceb

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 4320ceb

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
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: 20 additions & 2 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,12 +214,17 @@ 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',
221222
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages for two different changes in a single codebase and output them in the provided JSON format: one for a bug fix and another for a new feature.
222223
224+
IMPORTANT: You MUST write all commit messages and descriptions in ${
225+
translation.localLanguage
226+
}. Use the exact language and style shown in the example below.
227+
223228
Here are the specific requirements and conventions that should be strictly followed:
224229
225230
Commit Message Conventions:
@@ -247,9 +252,22 @@ JSON Output Format:
247252
- The "commitDescription" should not include the commit message's header, only the description.
248253
- Description should not be more than 74 characters.
249254
255+
Reference Example (you MUST follow this language and style):
256+
\`\`\`json
257+
{
258+
"localLanguage": "${translation.localLanguage}",
259+
"commitFix": "${translation.commitFix}",
260+
"commitFeat": "${translation.commitFeat}",
261+
"commitFixOmitScope": "${translation.commitFixOmitScope}",
262+
"commitFeatOmitScope": "${translation.commitFeatOmitScope}",
263+
"commitDescription": "${translation.commitDescription}"
264+
}
265+
\`\`\`
266+
250267
Additional Details:
251268
- Changing the variable 'port' to uppercase 'PORT' is considered a bug fix.
252269
- Allowing the server to listen on a port specified through the environment variable is considered a new feature.
270+
- Use the same language and writing style as shown in the reference example above.
253271
254272
Example Git Diff is to follow:`
255273
},

0 commit comments

Comments
 (0)