Skip to content

Commit a8454fa

Browse files
committed
Implement internationalization support for commit message generation and UI text
1 parent 105d478 commit a8454fa

12 files changed

Lines changed: 374 additions & 37 deletions

File tree

‎apps/editor/src/commands/generate-commit-message-command/generate-commit-message-command.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { get_commit_message_config } from './utils/get-commit-message-config'
88
import { build_commit_message_prompt } from './utils/build-commit-message-prompt'
99
import { generate_commit_message_with_api } from './utils/generate-commit-message-with-api'
1010
import { ModelProvidersManager } from '@/services/model-providers-manager'
11+
import { t } from '@/i18n'
1112

1213
export const generate_commit_message_command = (
1314
context: vscode.ExtensionContext
@@ -93,14 +94,14 @@ export const generate_commit_message_command = (
9394
(resolve) => {
9495
const input_box = vscode.window.createInputBox()
9596
input_box.value = commit_message
96-
input_box.title = 'Commit Message'
97-
input_box.prompt = 'Edit the commit message.'
97+
input_box.title = t('command.commit-message.input.title')
98+
input_box.prompt = t('command.commit-message.input.prompt')
9899

99100
if (has_default_config && !files_staged_by_action) {
100101
input_box.buttons = [
101102
{
102103
iconPath: new vscode.ThemeIcon('close'),
103-
tooltip: 'Close'
104+
tooltip: t('common.close')
104105
}
105106
]
106107
} else {
@@ -112,7 +113,7 @@ export const generate_commit_message_command = (
112113
input_box.onDidTriggerButton((button) => {
113114
if (
114115
button === vscode.QuickInputButtons.Back ||
115-
button.tooltip == 'Close'
116+
button.tooltip === t('common.close')
116117
) {
117118
is_resolved = true
118119
resolve('back')
@@ -189,9 +190,9 @@ export const generate_commit_message_command = (
189190
await vscode.env.clipboard.writeText(message_prompt)
190191
const token_count = Math.ceil(message_prompt.length / 4)
191192
vscode.window.showInformationMessage(
192-
`Commit message prompt of about ${display_token_count(
193-
token_count
194-
)} tokens copied to clipboard.`
193+
t('command.commit-message.copied', {
194+
tokens: display_token_count(token_count)
195+
})
195196
)
196197

197198
if (was_empty_stage) {

‎apps/editor/src/commands/generate-commit-message-command/utils/generate-commit-message-with-api.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { display_token_count } from '@/utils/display-token-count'
77
import { Logger } from '@shared/utils/logger'
88
import { strip_wrapping_quotes } from './strip-wrapping-quotes'
99
import { CommitMessageConfig } from './get-commit-message-config'
10+
import { t } from '@/i18n'
1011

1112
export const generate_commit_message_with_api = async (params: {
1213
endpoint_url: string
@@ -38,7 +39,7 @@ export const generate_commit_message_with_api = async (params: {
3839
return await vscode.window.withProgress(
3940
{
4041
location: vscode.ProgressLocation.Notification,
41-
title: 'Requested commit message',
42+
title: t('command.commit-message.progress.title'),
4243
cancellable: true
4344
},
4445
async (progress, token) => {
@@ -47,9 +48,9 @@ export const generate_commit_message_with_api = async (params: {
4748
})
4849

4950
progress.report({
50-
message: `sent ${display_token_count(
51-
Math.floor(params.message.length / 4)
52-
)} tokens...`
51+
message: t('common.progress.sent', {
52+
tokens: display_token_count(Math.floor(params.message.length / 4))
53+
})
5354
})
5455

5556
try {
@@ -59,10 +60,10 @@ export const generate_commit_message_with_api = async (params: {
5960
body,
6061
cancellation_token: cancel_token_source.token,
6162
on_chunk: () => {
62-
progress.report({ message: 'receiving...' })
63+
progress.report({ message: t('common.progress.receiving') })
6364
},
6465
on_thinking_chunk: () => {
65-
progress.report({ message: 'thinking...' })
66+
progress.report({ message: t('common.progress.thinking') })
6667
}
6768
})
6869

‎apps/editor/src/commands/generate-commit-message-command/utils/get-commit-message-config.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { dictionary } from '@shared/constants/dictionary'
99
import { Logger } from '@shared/utils/logger'
1010
import { PROVIDERS } from '@shared/constants/providers'
1111
import { RECENTLY_USED_COMMIT_MESSAGES_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
12+
import { t } from '@/i18n'
1213

1314
export interface CommitMessageConfig {
1415
provider_name: string
@@ -99,7 +100,7 @@ export const get_commit_message_config = async (
99100

100101
if (recent_configs.length > 0) {
101102
items.push({
102-
label: 'recently used',
103+
label: t('common.config.recently-used'),
103104
kind: vscode.QuickPickItemKind.Separator
104105
})
105106
items.push(...recent_configs.map(map_config_to_item))
@@ -108,7 +109,7 @@ export const get_commit_message_config = async (
108109
if (other_configs.length > 0) {
109110
if (recent_configs.length > 0) {
110111
items.push({
111-
label: 'other configurations',
112+
label: t('common.config.other'),
112113
kind: vscode.QuickPickItemKind.Separator
113114
})
114115
}
@@ -126,14 +127,14 @@ export const get_commit_message_config = async (
126127
quick_pick.buttons = [
127128
{
128129
iconPath: new vscode.ThemeIcon('close'),
129-
tooltip: 'Close'
130+
tooltip: t('common.close')
130131
}
131132
]
132133
}
133134

134135
quick_pick.items = create_items()
135-
quick_pick.title = 'Configurations'
136-
quick_pick.placeholder = 'Select configuration'
136+
quick_pick.title = t('common.config.title')
137+
quick_pick.placeholder = t('common.config.placeholder')
137138
quick_pick.matchOnDescription = true
138139

139140
const items = quick_pick.items as (vscode.QuickPickItem & {
@@ -156,7 +157,7 @@ export const get_commit_message_config = async (
156157
if (button === vscode.QuickInputButtons.Back) {
157158
quick_pick.hide()
158159
resolve('back')
159-
} else if (button.tooltip === 'Close') {
160+
} else if (button.tooltip === t('common.close')) {
160161
quick_pick.hide()
161162
resolve(undefined)
162163
}

‎apps/editor/src/i18n/index.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from 'vscode'
2+
import { translations } from './translations'
3+
4+
export type TranslationKey = keyof typeof translations
5+
6+
export const t = (
7+
key: TranslationKey,
8+
placeholders?: Record<string, string | number>
9+
): string => {
10+
const item = translations[key]
11+
if (!item) return key
12+
13+
const lang = vscode.env.language || 'en'
14+
15+
let text: string = item[lang as keyof typeof item]
16+
17+
if (!text) {
18+
const short_lang = lang.split('-')[0]
19+
text = item[short_lang as keyof typeof item]
20+
}
21+
22+
if (!text) {
23+
text = item['en'] || key
24+
}
25+
26+
if (placeholders) {
27+
for (const [k, v] of Object.entries(placeholders)) {
28+
text = text.replace(new RegExp(`\\{${k}\\}`, 'g'), String(v))
29+
}
30+
}
31+
32+
return text
33+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
export const commands = {
2+
'command.commit-message.input.title': {
3+
en: 'Commit Message',
4+
pl: 'Wiadomość commita',
5+
'zh-cn': '提交信息',
6+
ja: 'コミットメッセージ',
7+
'zh-tw': '提交訊息',
8+
de: 'Commit-Nachricht',
9+
es: 'Mensaje de commit',
10+
fr: 'Message de commit',
11+
'pt-br': 'Mensagem de commit',
12+
ru: 'Сообщение коммита',
13+
ko: '커밋 메시지',
14+
it: 'Messaggio di commit',
15+
tr: 'İşleme (Commit) Mesajı',
16+
cs: 'Zpráva commitu',
17+
hu: 'Commit üzenet',
18+
bg: 'Commit съобщение'
19+
},
20+
'command.commit-message.input.prompt': {
21+
en: 'Edit the commit message.',
22+
pl: 'Edytuj wiadomość commita.',
23+
'zh-cn': '编辑提交信息。',
24+
ja: 'コミットメッセージを編集します。',
25+
'zh-tw': '編輯提交訊息。',
26+
de: 'Bearbeiten Sie die Commit-Nachricht.',
27+
es: 'Edita el mensaje de commit.',
28+
fr: 'Modifiez le message de commit.',
29+
'pt-br': 'Edite a mensagem de commit.',
30+
ru: 'Отредактируйте сообщение коммита.',
31+
ko: '커밋 메시지를 편집합니다.',
32+
it: 'Modifica il messaggio di commit.',
33+
tr: 'İşleme (commit) mesajını düzenleyin.',
34+
cs: 'Upravte zprávu commitu.',
35+
hu: 'Szerkessze a commit üzenetet.',
36+
bg: 'Редактирайте commit съобщението.'
37+
},
38+
'command.commit-message.copied': {
39+
en: 'Commit message prompt of about {tokens} tokens copied to clipboard.',
40+
pl: 'Prompt wiadomości commita składający się z około {tokens} tokenów skopiowany do schowka.',
41+
'zh-cn': '包含约 {tokens} 个 token 的提交信息提示词已复制到剪贴板。',
42+
ja: '約 {tokens} トークンのコミットメッセージプロンプトがクリップボードにコピーされました。',
43+
'zh-tw': '包含約 {tokens} 個 token 的提交訊息提示詞已複製到剪貼簿。',
44+
de: 'Commit-Nachrichten-Prompt von etwa {tokens} Token in die Zwischenablage kopiert.',
45+
es: 'El prompt del mensaje de commit de unos {tokens} tokens se ha copiado en el portapapeles.',
46+
fr: "Le prompt du message de commit d'environ {tokens} jetons a été copié dans le presse-papiers.",
47+
'pt-br':
48+
'Prompt de mensagem de commit de cerca de {tokens} tokens copiado para a área de transferência.',
49+
ru: 'Промпт сообщения коммита из примерно {tokens} токенов скопирован в буфер обмена.',
50+
ko: '약 {tokens} 토큰의 커밋 메시지 프롬프트가 클립보드에 복사되었습니다.',
51+
it: 'Prompt del messaggio di commit di circa {tokens} token copiato negli appunti.',
52+
tr: 'Yaklaşık {tokens} tokenlık işleme mesajı istemi panoya kopyalandı.',
53+
cs: 'Prompt zprávy commitu o velikosti přibližně {tokens} tokenů zkopírován do schránky.',
54+
hu: 'Körülbelül {tokens} tokenből álló commit üzenet prompt a vágólapra másolva.',
55+
bg: 'Промптът за commit съобщение от около {tokens} токена е копиран в клипборда.'
56+
},
57+
'command.commit-message.progress.title': {
58+
en: 'Requested commit message',
59+
pl: 'Zażądano wiadomości commita',
60+
'zh-cn': '已请求提交信息',
61+
ja: 'コミットメッセージをリクエストしました',
62+
'zh-tw': '已請求提交訊息',
63+
de: 'Commit-Nachricht angefordert',
64+
es: 'Mensaje de commit solicitado',
65+
fr: 'Message de commit demandé',
66+
'pt-br': 'Mensagem de commit solicitada',
67+
ru: 'Запрошено сообщение коммита',
68+
ko: '요청된 커밋 메시지',
69+
it: 'Messaggio di commit richiesto',
70+
tr: 'İşleme mesajı istendi',
71+
cs: 'Vyžádána zpráva commitu',
72+
hu: 'Commit üzenet lekérve',
73+
bg: 'Заявено е commit съобщение'
74+
},
75+
'command.commit-message.select-repository': {
76+
en: 'Select a repository to generate the commit message for',
77+
pl: 'Wybierz repozytorium, dla którego chcesz wygenerować wiadomość commita',
78+
'zh-cn': '选择要生成提交信息的仓库',
79+
ja: 'コミットメッセージを生成するリポジトリを選択してください',
80+
'zh-tw': '選擇要產生提交訊息的儲存庫',
81+
de: 'Wählen Sie ein Repository aus, für das die Commit-Nachricht generiert werden soll',
82+
es: 'Seleccione un repositorio para generar el mensaje de commit',
83+
fr: 'Sélectionnez un dépôt pour générer le message de commit',
84+
'pt-br': 'Selecione um repositório para gerar a mensagem de commit',
85+
ru: 'Выберите репозиторий для генерации сообщения коммита',
86+
ko: '커밋 메시지를 생성할 저장소 선택',
87+
it: 'Seleziona un repository per generare il messaggio di commit',
88+
tr: 'İşleme mesajı oluşturmak için bir depo seçin',
89+
cs: 'Vyberte repozitář pro vygenerování zprávy commitu',
90+
hu: 'Válasszon egy tárolót a commit üzenet generálásához',
91+
bg: 'Изберете хранилище за генериране на commit съобщение'
92+
},
93+
'command.commit-message.unstaged-files': {
94+
en: 'Unstaged Files',
95+
pl: 'Nieprzygotowane pliki',
96+
'zh-cn': '未暂存的文件',
97+
ja: 'ステージされていないファイル',
98+
'zh-tw': '未暫存的檔案',
99+
de: 'Nicht bereitgestellte Dateien',
100+
es: 'Archivos no preparados',
101+
fr: 'Fichiers non indexés',
102+
'pt-br': 'Arquivos não preparados',
103+
ru: 'Неиндексированные файлы',
104+
ko: '스테이징되지 않은 파일',
105+
it: 'File non in stage',
106+
tr: 'Hazırlanmamış (Unstaged) Dosyalar',
107+
cs: 'Nepřipravené soubory',
108+
hu: 'Nem előkészített fájlok',
109+
bg: 'Неиндексирани файлове'
110+
},
111+
'command.commit-message.select-files': {
112+
en: 'Select files to commit',
113+
pl: 'Wybierz pliki do zatwierdzenia',
114+
'zh-cn': '选择要提交的文件',
115+
ja: 'コミットするファイルを選択',
116+
'zh-tw': '選擇要提交的檔案',
117+
de: 'Dateien zum Committen auswählen',
118+
es: 'Seleccionar archivos para el commit',
119+
fr: 'Sélectionner les fichiers à commiter',
120+
'pt-br': 'Selecione os arquivos para commit',
121+
ru: 'Выберите файлы для коммита',
122+
ko: '커밋할 파일 선택',
123+
it: 'Seleziona i file per il commit',
124+
tr: 'İşlenecek dosyaları seçin',
125+
cs: 'Vyberte soubory k commitnutí',
126+
hu: 'Válassza ki a commitolandó fájlokat',
127+
bg: 'Изберете файлове за commit'
128+
}
129+
} as const

0 commit comments

Comments
 (0)