From 4097586a3478712f86fae608a426cc57483a6454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hegyi=20=C3=81ron=20Ferenc?= <36823200+Rettend@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:47:24 +0200 Subject: [PATCH 1/2] feat: debug mode --- README.md | 2 +- src/cli.ts | 3 +++ src/config.ts | 13 +++++++++++++ src/utils.ts | 7 ++----- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a901f9c..7bce520 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # lin -![NPM Version](https://img.shields.io/npm/v/%40yuo-app%2Flin) +![NPM Version](https://img.shields.io/npm/v/%40yuo-app%2Flin?color=red) ![JSR Version](https://img.shields.io/jsr/v/%40yuo/lin?color=yellow) auto-i18n diff --git a/src/cli.ts b/src/cli.ts index fa95fc3..3fa58f2 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -25,6 +25,9 @@ const main = defineCommand({ if (rawArgs.length === 0) showUsage(cmd) + + if (args.debug) + console.log(args) }, }) diff --git a/src/config.ts b/src/config.ts index e50154b..5a80fd7 100644 --- a/src/config.ts +++ b/src/config.ts @@ -52,6 +52,12 @@ export interface Config { * the OpenAI options, like the model to use */ options: OpenAIOptions + + /** + * DEBUG mode + * @default false + */ + debug: boolean } export const DEFAULT_CONFIG = { @@ -62,6 +68,7 @@ export const DEFAULT_CONFIG = { model: 'gpt-4o-mini', temperature: 0, }, + debug: false, } satisfies Config type Args = { @@ -101,6 +108,12 @@ export const commonArgs: Args = { description: 'the temperature to use', default: DEFAULT_CONFIG.options.temperature.toString(), }, + debug: { + alias: 'd', + type: 'boolean', + description: 'debug mode', + default: DEFAULT_CONFIG.debug, + }, } export const models: ChatModel[] = [ diff --git a/src/utils.ts b/src/utils.ts index 061529f..391574c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -65,7 +65,7 @@ export const ICONS = { function formatLog(message: any): string { if (typeof message !== 'string') - message = String(message) + return message return (message as string) .replace(/`([^`]+)`/g, (_, p1) => `${c.cyan(p1)}`) @@ -93,10 +93,7 @@ function createLoadingIndicator(message: string) { class ConsoleExtended extends Console { log(...messages: any[]): void { - if (typeof messages[0] === 'string') - super.log(...messages.map(formatLog)) - else - super.log(...messages) + super.log(...messages.map(formatLog)) } async loading(message: string, callback: () => Promise): Promise { From da1dfee649c1df29c585d80f255525f9a0356b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hegyi=20=C3=81ron=20Ferenc?= <36823200+Rettend@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:44:09 +0200 Subject: [PATCH 2/2] docs: update toood --- TODO.md | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 9625477..21d2da9 100644 --- a/TODO.md +++ b/TODO.md @@ -1,15 +1,30 @@ # TODO -- [ ] `translate` command - - [x] Base functionality: translates all locales - - [x] skip locale json files that are completely translated - - [ ] if there is an incomplete local json, then the gpt will add the missing parts (still put everything in the context window) - - [ ] Usage with `--manual [key]`: Prompts the user to enter the translation for each key in all the locales that are not yet translated. If a key is specified then all languages are prompted. -- [ ] `add` command (`lin add `) - - [ ] Default usage: Running `lin add ` prompts the user to enter the translation for the key in the default language. It is then automatically translated to all the locales and saved in the locale json files. - - [ ] If a key already exists, show error and prompt to use `lin translate --manual [key]` instead. - - [ ] Usage with `--locale`: Prompts the user to enter the translation for the key in the specified locale. - - [ ] Usage with `--manual`: Prompts the user to enter the translation for the key for all the locales. -- [ ] `convert` command +## v0.1.0 + +- [ ] **`translate [...locales]`**: sync all locale json files with the default locale json file. + - [x] translates all locales, skip locales that exactly match the default locale + - [ ] find missing keys in locales, add placeholder strings, get translations with one gpt request, put translations back to their correct places + - [ ] if no locales are provided, then prompt the user to translate them + - **options:** + - [x] `-f, --force`: force to translate all locales + +- [ ] **`add [...text]`**: add a key (or more keys) to the default locale json file, and translate it to all the locales. + - [ ] if key already exists, show error and prompt to use + - **options:** + - [ ] `-l, --locale `: translate only the specified locale + - [ ] `-f, --force`: force to translate the key even if it already exists + +- [ ] locales: `all` is every locale, `def` is the default locale, and `en` is a shorthand for `en-**` + +- [ ] **`verify`**: check everything is setup correctly. + +- [ ] **context window:** provide a way to add extra information to the gpt request + - [ ] `context: string` config: this just gets added to the prompt by default + - `-w, --with [locale]` + - [ ] `string` commonarg: add a locale json to the prompt + - [ ] `boolean` commonarg: do not add the context string to the prompt + +- [ ] **`convert` command:** convert a project to use i18n by extracting all the strings from the code and adding them to the locale json files. - [ ] i18n loader - [ ] support for other i18n integrations