Skip to content

Commit 4d11e61

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 4d11e61

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-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: 18 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,15 @@ 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 ${translation.localLanguage}. Use the exact language and style shown in the example below.
225+
223226
Here are the specific requirements and conventions that should be strictly followed:
224227
225228
Commit Message Conventions:
@@ -247,9 +250,22 @@ JSON Output Format:
247250
- The "commitDescription" should not include the commit message's header, only the description.
248251
- Description should not be more than 74 characters.
249252
253+
Reference Example (you MUST follow this language and style):
254+
\`\`\`json
255+
{
256+
"localLanguage": "${translation.localLanguage}",
257+
"commitFix": "${translation.commitFix}",
258+
"commitFeat": "${translation.commitFeat}",
259+
"commitFixOmitScope": "${translation.commitFixOmitScope}",
260+
"commitFeatOmitScope": "${translation.commitFeatOmitScope}",
261+
"commitDescription": "${translation.commitDescription}"
262+
}
263+
\`\`\`
264+
250265
Additional Details:
251266
- Changing the variable 'port' to uppercase 'PORT' is considered a bug fix.
252267
- Allowing the server to listen on a port specified through the environment variable is considered a new feature.
268+
- Use the same language and writing style as shown in the reference example above.
253269
254270
Example Git Diff is to follow:`
255271
},

0 commit comments

Comments
 (0)