Skip to content

Commit

Permalink
Merge pull request #6 from yuo-app/rettend
Browse files Browse the repository at this point in the history
Rettend
  • Loading branch information
Rettend authored Aug 30, 2024
2 parents 99d9668 + da1dfee commit 824bda4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
37 changes: 26 additions & 11 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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 <key>`)
- [ ] Default usage: Running `lin add <key>` 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 <key> [...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 <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
3 changes: 3 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const main = defineCommand({

if (rawArgs.length === 0)
showUsage(cmd)

if (args.debug)
console.log(args)
},
})

Expand Down
13 changes: 13 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -62,6 +68,7 @@ export const DEFAULT_CONFIG = {
model: 'gpt-4o-mini',
temperature: 0,
},
debug: false,
} satisfies Config

type Args = {
Expand Down Expand Up @@ -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[] = [
Expand Down
7 changes: 2 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`)
Expand Down Expand Up @@ -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<T>(message: string, callback: () => Promise<T>): Promise<T> {
Expand Down

0 comments on commit 824bda4

Please sign in to comment.