Skip to content

Commit d11d5e8

Browse files
authored
Merge pull request #10 from 4DRIAN0RTIZ/main
✨ feat (locales): introduces locale file for language support
2 parents a08bbcf + 3e3d0fc commit d11d5e8

File tree

4 files changed

+227
-34
lines changed

4 files changed

+227
-34
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
https://github.com/user-attachments/assets/b6e6aa6c-85a8-42b1-994c-fa3ffe80d760
66

77
## Features
8+
89
- **Automated Commit Message Generation** – Analyzes changes (git diff) and generates commit messages automatically.
910
- **AI-Powered Suggestions** – UsesAI to create meaningful commit messages.
1011
- **Multiple Commit Message Options** – Provides different commit types (feat, fix, chore, enhancement, etc.).
12+
- **Multiple Commit Languages** – Supports multiple commit message languages.
1113

1214
## Requirements
1315

@@ -16,7 +18,6 @@ https://github.com/user-attachments/assets/b6e6aa6c-85a8-42b1-994c-fa3ffe80d760
1618
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
1719
- An API key for at least one of the supported AI providers
1820

19-
2021
## Installation
2122

2223
### Lazy
@@ -31,6 +32,7 @@ https://github.com/user-attachments/assets/b6e6aa6c-85a8-42b1-994c-fa3ffe80d760
3132
config = function()
3233
require('commit-ai').setup {
3334
icons = false,
35+
language = 'en', -- default language
3436
-- unopiniated commit conventions
3537
git_conventions = {
3638
docs = { icon = "📖", prefix = "docs", type = "Documentation changes" },
@@ -54,9 +56,9 @@ https://github.com/user-attachments/assets/b6e6aa6c-85a8-42b1-994c-fa3ffe80d760
5456

5557
## Usage
5658

57-
| Command | Description |
58-
| --------------------- | ------------------------------------------------------- |
59-
| `:Commit` | Generate a commit message suggestions with AI |
59+
| Command | Description |
60+
| --------- | --------------------------------------------- |
61+
| `:Commit` | generate a commit message suggestions with AI |
6062

6163
## Contributing
6264

lua/commit-ai/config.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
-- default config
22
local M = {
33
-- define for adding icon to your commit msg
4-
icons = false
4+
icons = false,
5+
language = 'en',
56
}
67

78
-- unopiniated commit conventions

lua/commit-ai/locales.lua

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
-- lua/commit_ai/locales.lua
2+
return {
3+
en = "English",
4+
es = "Spanish",
5+
fr = "French",
6+
de = "German",
7+
it = "Italian",
8+
pt = "Portuguese",
9+
ru = "Russian",
10+
zh = "Chinese",
11+
ja = "Japanese",
12+
ko = "Korean",
13+
ar = "Arabic",
14+
hi = "Hindi",
15+
bn = "Bengali",
16+
pa = "Punjabi",
17+
jv = "Javanese",
18+
ms = "Malay",
19+
vi = "Vietnamese",
20+
tr = "Turkish",
21+
fa = "Persian",
22+
pl = "Polish",
23+
nl = "Dutch",
24+
sv = "Swedish",
25+
no = "Norwegian",
26+
da = "Danish",
27+
fi = "Finnish",
28+
el = "Greek",
29+
he = "Hebrew",
30+
th = "Thai",
31+
id = "Indonesian",
32+
ro = "Romanian",
33+
hu = "Hungarian",
34+
cs = "Czech",
35+
sk = "Slovak",
36+
uk = "Ukrainian",
37+
sr = "Serbian",
38+
hr = "Croatian",
39+
bg = "Bulgarian",
40+
lt = "Lithuanian",
41+
lv = "Latvian",
42+
et = "Estonian",
43+
sl = "Slovenian",
44+
sq = "Albanian",
45+
mk = "Macedonian",
46+
sw = "Swahili",
47+
af = "Afrikaans",
48+
zu = "Zulu",
49+
xh = "Xhosa",
50+
am = "Amharic",
51+
yo = "Yoruba",
52+
ig = "Igbo",
53+
ha = "Hausa",
54+
ta = "Tamil",
55+
te = "Telugu",
56+
ml = "Malayalam",
57+
kn = "Kannada",
58+
mr = "Marathi",
59+
gu = "Gujarati",
60+
ur = "Urdu",
61+
ne = "Nepali",
62+
si = "Sinhala",
63+
my = "Burmese",
64+
km = "Khmer",
65+
lo = "Lao",
66+
mn = "Mongolian",
67+
ka = "Georgian",
68+
hy = "Armenian",
69+
az = "Azerbaijani",
70+
uz = "Uzbek",
71+
kk = "Kazakh",
72+
tk = "Turkmen",
73+
ky = "Kyrgyz",
74+
tg = "Tajik",
75+
ps = "Pashto",
76+
sd = "Sindhi",
77+
uz = "Uzbek",
78+
kk = "Kazakh",
79+
be = "Belarusian",
80+
eo = "Esperanto",
81+
ga = "Irish",
82+
cy = "Welsh",
83+
gd = "Scottish Gaelic",
84+
br = "Breton",
85+
oc = "Occitan",
86+
eu = "Basque",
87+
gl = "Galician",
88+
ca = "Catalan",
89+
lb = "Luxembourgish",
90+
is = "Icelandic",
91+
mt = "Maltese",
92+
bs = "Bosnian",
93+
mk = "Macedonian",
94+
sq = "Albanian",
95+
lv = "Latvian",
96+
lt = "Lithuanian",
97+
fo = "Faroese",
98+
sm = "Samoan",
99+
fj = "Fijian",
100+
mi = "Maori",
101+
haw = "Hawaiian",
102+
to = "Tongan",
103+
mg = "Malagasy",
104+
rw = "Kinyarwanda",
105+
rn = "Kirundi",
106+
so = "Somali",
107+
st = "Sesotho",
108+
tn = "Tswana",
109+
ts = "Tsonga",
110+
ve = "Venda",
111+
wo = "Wolof",
112+
sn = "Shona",
113+
ny = "Chichewa",
114+
lg = "Luganda",
115+
ln = "Lingala",
116+
kg = "Kongo",
117+
qu = "Quechua",
118+
ay = "Aymara",
119+
gn = "Guarani",
120+
ht = "Haitian Creole",
121+
cr = "Cree",
122+
oj = "Ojibwe",
123+
ch = "Chamorro",
124+
ty = "Tahitian",
125+
pi = "Pali",
126+
sa = "Sanskrit",
127+
bo = "Tibetan",
128+
dz = "Dzongkha",
129+
ti = "Tigrinya",
130+
om = "Oromo",
131+
rw = "Kinyarwanda",
132+
lg = "Luganda",
133+
ss = "Swati",
134+
ve = "Venda",
135+
ts = "Tsonga",
136+
tn = "Tswana",
137+
st = "Sesotho",
138+
nr = "South Ndebele",
139+
nso = "Northern Sotho",
140+
zu = "Zulu",
141+
xh = "Xhosa",
142+
af = "Afrikaans",
143+
am = "Amharic",
144+
om = "Oromo",
145+
ti = "Tigrinya",
146+
so = "Somali",
147+
rn = "Kirundi",
148+
mg = "Malagasy",
149+
ny = "Chichewa",
150+
sn = "Shona",
151+
sg = "Sango",
152+
ln = "Lingala",
153+
kg = "Kongo",
154+
lo = "Lao",
155+
km = "Khmer",
156+
my = "Burmese",
157+
th = "Thai",
158+
vi = "Vietnamese",
159+
id = "Indonesian",
160+
ms = "Malay",
161+
jv = "Javanese",
162+
su = "Sundanese",
163+
tl = "Tagalog",
164+
ceb = "Cebuano",
165+
fil = "Filipino",
166+
pap = "Papiamento",
167+
haw = "Hawaiian",
168+
sm = "Samoan",
169+
fj = "Fijian",
170+
mi = "Maori",
171+
ty = "Tahitian",
172+
to = "Tongan",
173+
}

lua/commit-ai/prompt.lua

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,52 @@
1+
local locales = require('commit-ai.locales')
2+
local _plugin
3+
4+
local function get_plugin()
5+
if not _plugin then
6+
_plugin = require('commit-ai')
7+
end
8+
return _plugin
9+
end
10+
111
local M = {}
212

313
function M.default_prompt(diff, format_lines)
4-
return string.format(
5-
[[
6-
Analyze the following Git diff and suggest commit messages.
7-
8-
Follow this format exactly:
9-
- <icon> <prefix> (<scope>): <commit message>
10-
11-
Choose an appropriate <icon> and <prefix> from the list below based on the type of change:
12-
13-
%s
14-
15-
Commit rules:
16-
1. Only use the above icons and prefixes.
17-
2. Use "chore" for configuration files (*.yml, *.json, *.env), CI/CD changes, build systems, or general non-code tasks.
18-
3. Use "fix" for bug fixes.
19-
4. Use "feat" ONLY for user-facing features or newly introduced functionality.
20-
5. Use "docs" for documentation-only changes, including README.md and LICENSE.
21-
6. Use "refactor" for breaking internal code changes that don’t affect functionality.
22-
7. Use "enhance" for performance improvements or minor internal enhancements.
23-
8. The <scope> should desribe the affected module or file group or folder.
24-
9. Keep commit message should be concise and written in the imperative mood (e.g., "add config for <context>
25-
10. Only use lowercase letters in the commit message.
26-
27-
Git diff:
28-
%s
29-
]],
30-
table.concat(format_lines, "\n"),
31-
diff
32-
)
14+
local config = get_plugin().config
15+
16+
local header = table.concat({
17+
"Analyze the following Git diff and suggest commit messages.",
18+
"",
19+
"Follow this format exactly:",
20+
"- <icon> <prefix> (<scope>): <commit message>",
21+
"",
22+
"Commit rules:",
23+
"0. Use " .. locales[config.language] .. " for commit messages.",
24+
"1. Only use the above icons and prefixes.",
25+
"2. Use \"chore\" for configuration files (*.yml, *.json, *.env), CI/CD changes, build systems, or general non-code tasks.",
26+
"3. Use \"fix\" for bug fixes.",
27+
"4. Use \"feat\" ONLY for user-facing features or newly introduced functionality.",
28+
"5. Use \"docs\" for documentation-only changes, including README.md and LICENSE.",
29+
"6. Use \"refactor\" for breaking internal code changes that don’t affect functionality.",
30+
"7. Use \"enhance\" for performance improvements or minor internal enhancements.",
31+
"8. The <scope> should describe the affected module, file group or folder.",
32+
"9. Keep commit message concise and written in the imperative mood.",
33+
"10. Only use lowercase letters in the commit message.",
34+
"",
35+
}, "\n")
36+
37+
local conventions_block = table.concat(format_lines, "\n")
38+
39+
local diff_block = "\n\nGit diff:\n" .. diff
40+
41+
local lang_name = locales[config.language] or locales.en
42+
43+
local footer = ("\n\nLanguage: %s\n\n" ..
44+
"Please provide the commit message in the format specified above."):format(lang_name)
45+
46+
return header
47+
.. conventions_block
48+
.. diff_block
49+
.. footer
3350
end
3451

3552
return M

0 commit comments

Comments
 (0)