diff --git a/src/commands/config.ts b/src/commands/config.ts index e104035..e0a7123 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -6,11 +6,13 @@ import { homedir } from 'os'; import { intro, outro } from '@clack/prompts'; import chalk from 'chalk'; import { COMMANDS } from '../CommandsEnum'; +import { getI18nLocal } from '../i18n'; export enum CONFIG_KEYS { OPENAI_API_KEY = 'OPENAI_API_KEY', description = 'description', - emoji = 'emoji' + emoji = 'emoji', + language = 'language' } export enum CONFIG_MODES { @@ -64,6 +66,14 @@ export const configValidators = { ); return value; + }, + [CONFIG_KEYS.language](value: any) { + validateConfig( + CONFIG_KEYS.language, + getI18nLocal(value), + `${value} is not supported yet` + ); + return getI18nLocal(value); } }; diff --git a/src/generateCommitMessageFromGitDiff.ts b/src/generateCommitMessageFromGitDiff.ts index adfb5b9..7bfd3bf 100644 --- a/src/generateCommitMessageFromGitDiff.ts +++ b/src/generateCommitMessageFromGitDiff.ts @@ -5,8 +5,10 @@ import { import { api } from './api'; import { getConfig } from './commands/config'; import { mergeStrings } from './utils/mergeStrings'; +import { i18n, I18nLocals } from './i18n'; const config = getConfig(); +const translation = i18n[config?.language as I18nLocals || 'en'] const INIT_MESSAGES_PROMPT: Array = [ { @@ -18,8 +20,8 @@ const INIT_MESSAGES_PROMPT: Array = [ }, use the present tense. ${ config?.description ? 'Add a short description of what commit is about after the commit message. Don\'t start it with "This commit", just describe the changes.' - : "Don't add any descriptions to the commit, only commit message." - }` + : 'Don\'t add any descriptions to the commit, only commit message.' + } Use ${translation.localLanguage} to answer.}` }, { role: ChatCompletionRequestMessageRoleEnum.User, @@ -48,10 +50,9 @@ const INIT_MESSAGES_PROMPT: Array = [ }, { role: ChatCompletionRequestMessageRoleEnum.Assistant, - // prettier-ignore - content: `${config?.emoji ? '🐛 ' : ''}fix(server.ts): change port variable case from lowercase port to uppercase PORT -${config?.emoji ? '✨ ' : ''}feat(server.ts): add support for process.env.PORT environment variable -${config?.description ? 'The port variable is now named PORT, which improves consistency with the naming conventions as PORT is a constant. Support for an environment variable allows the application to be more flexible as it can now run on any available port specified via the process.env.PORT environment variable.' : ''}` + content: `${config?.emoji ? '🐛 ' : ''}${translation.commitFix} +${config?.emoji ? '✨ ' : ''}${translation.commitFeat} +${config?.description ? translation.commitDescription : ''}` } ]; diff --git a/src/i18n/de.json b/src/i18n/de.json new file mode 100644 index 0000000..6e65c14 --- /dev/null +++ b/src/i18n/de.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "Deutsch", + "commitFix": "fix(server.ts): Ändere die Groß- und Kleinschreibung der Port-Variable von Kleinbuchstaben auf Großbuchstaben PORT.", + "commitFeat": "Funktion(server.ts): Unterstützung für die Umgebungsvariable process.env.PORT hinzufügen", + "commitDescription": "Die Port-Variable heißt jetzt PORT, was die Konsistenz mit den Namenskonventionen verbessert, da PORT eine Konstante ist. Die Unterstützung für eine Umgebungsvariable ermöglicht es der Anwendung, flexibler zu sein, da sie jetzt auf jedem verfügbaren Port laufen kann, der über die Umgebungsvariable process.env.PORT angegeben wird." +} diff --git a/src/i18n/en.json b/src/i18n/en.json new file mode 100644 index 0000000..66ec749 --- /dev/null +++ b/src/i18n/en.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "english", + "commitFix": "fix(server.ts): change port variable case from lowercase port to uppercase PORT", + "commitFeat": "feat(server.ts): add support for process.env.PORT environment variable", + "commitDescription": "The port variable is now named PORT, which improves consistency with the naming conventions as PORT is a constant. Support for an environment variable allows the application to be more flexible as it can now run on any available port specified via the process.env.PORT environment variable." +} diff --git a/src/i18n/fr.json b/src/i18n/fr.json new file mode 100644 index 0000000..2e6c079 --- /dev/null +++ b/src/i18n/fr.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "française", + "commitFix": "corriger(server.ts) : changer la casse de la variable de port de minuscules à majuscules (PORT)", + "commitFeat": "fonctionnalité(server.ts) : ajouter la prise en charge de la variable d'environnement process.env.PORT", + "commitDescription": "La variable de port est maintenant nommée PORT, ce qui améliore la cohérence avec les conventions de nommage car PORT est une constante. La prise en charge d'une variable d'environnement permet à l'application d'être plus flexible car elle peut maintenant s'exécuter sur n'importe quel port disponible spécifié via la variable d'environnement process.env.PORT." +} diff --git a/src/i18n/index.ts b/src/i18n/index.ts new file mode 100644 index 0000000..27590cc --- /dev/null +++ b/src/i18n/index.ts @@ -0,0 +1,50 @@ +import en from '../i18n/en.json' assert { type: 'json' }; +import de from '../i18n/de.json' assert { type: 'json' }; +import fr from '../i18n/fr.json' assert { type: 'json' }; +import it from '../i18n/it.json' assert { type: 'json' }; +import ko from '../i18n/ko.json' assert { type: 'json' }; +import zh_CN from '../i18n/zh_CN.json' assert { type: 'json' }; +import zh_TW from '../i18n/zh_TW.json' assert { type: 'json' }; +import ja from '../i18n/ja.json' assert { type: 'json' }; + +export enum I18nLocals { + 'en' = 'en', + 'zh_CN' = 'zh_CN', + 'zh_TW' = 'zh_TW', + 'ja' = 'ja', + 'de' = 'de', + 'fr' = 'fr', + 'it' = 'it', + 'ko' = 'ko' +}; + +export const i18n = { + en, + zh_CN, + zh_TW, + ja, + de, + fr, + it, + ko, +}; + +export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = { + zh_CN: ['zh_CN', '简体中文', '中文', '简体'], + zh_TW: ['zh_TW', '繁體中文', '繁體'], + ja: ['ja', 'Japanese', 'にほんご'], + ko: ['ko', 'Korean', '한국어'], + de: ['de', 'German' ,'Deutsch'], + fr: ['fr', 'French', 'française'], + it: ['it', 'Italian', 'italiano'], +}; + +export function getI18nLocal(value: string): string | boolean { + for (const key in I18N_CONFIG_ALIAS) { + const aliases = I18N_CONFIG_ALIAS[key]; + if (aliases.includes(value)) { + return key; + } + } + return false; +} diff --git a/src/i18n/it.json b/src/i18n/it.json new file mode 100644 index 0000000..8994073 --- /dev/null +++ b/src/i18n/it.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "italiano", + "commitFix": "fix(server.ts): cambia il caso della variabile di porta da minuscolo port a maiuscolo PORT", + "commitFeat": "funzionalità(server.ts): aggiungi supporto per la variabile di ambiente process.env.PORT", + "commitDescription": "La variabile di porta è ora chiamata PORT, il che migliora la coerenza con le convenzioni di denominazione in quanto PORT è una costante. Il supporto per una variabile di ambiente consente all'applicazione di essere più flessibile poiché ora può essere eseguita su qualsiasi porta disponibile specificata tramite la variabile di ambiente process.env.PORT." +} diff --git a/src/i18n/ja.json b/src/i18n/ja.json new file mode 100644 index 0000000..9d529be --- /dev/null +++ b/src/i18n/ja.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "にほんご", + "commitFix": "修正(server.ts): ポート変数のケースを小文字のポートから大文字のPORTに変更", + "commitFeat": "新機能(server.ts): process.env.PORT環境変数のサポートを追加する", + "commitDescription": "ポート変数は現在PORTという名前になっており、PORTは定数であるため命名規則に一貫性があります。環境変数のサポートにより、アプリケーションはより柔軟になり、process.env.PORT環境変数で指定された任意の利用可能なポートで実行できるようになりまし" +} diff --git a/src/i18n/ko.json b/src/i18n/ko.json new file mode 100644 index 0000000..cdf511d --- /dev/null +++ b/src/i18n/ko.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "한국어", + "commitFix": "fix(server.ts): 포트 변수를 소문자 port에서 대문자 PORT로 변경", + "commitFeat": "피트(server.ts): process.env.PORT 환경 변수 지원 추가", + "commitDescription": "포트 변수는 이제 PORT로 이름이 지정되어 상수인 PORT와 일관성 있는 이름 규칙을 따릅니다. 환경 변수 지원을 통해 애플리케이션은 이제 process.env.PORT 환경 변수로 지정된 사용 가능한 모든 포트에서 실행할 수 있으므로 더 유연해졌습니다." +} diff --git a/src/i18n/zh_CN.json b/src/i18n/zh_CN.json new file mode 100644 index 0000000..897ffc1 --- /dev/null +++ b/src/i18n/zh_CN.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "简体中文", + "commitFix": "修复(server.ts):将端口变量从小写port改为大写PORT", + "commitFeat": "功能(server.ts):添加对process.env.PORT环境变量的支持", + "commitDescription": "现在端口变量被命名为PORT,这提高了命名约定的一致性,因为PORT是一个常量。环境变量的支持使应用程序更加灵活,因为它现在可以通过process.env.PORT环境变量在任何可用端口上运行。" +} diff --git a/src/i18n/zh_TW.json b/src/i18n/zh_TW.json new file mode 100644 index 0000000..f3f85fb --- /dev/null +++ b/src/i18n/zh_TW.json @@ -0,0 +1,6 @@ +{ + "localLanguage": "繁體中文", + "commitFix": "修正(server.ts):將端口變數從小寫端口改為大寫PORT", + "commitFeat": "功能(server.ts):新增對process.env.PORT環境變數的支援", + "commitDescription": "現在port變數已更名為PORT,以符合命名慣例,因為PORT是一個常量。支援環境變數可以使應用程序更靈活,因為它現在可以通過process.env.PORT環境變數運行在任何可用端口上。" +}