Skip to content

Commit 83e2918

Browse files
committed
chore(.gitignore): add playground directory to ignore list
docs(README.md): update command examples to include 'translate' keyword feat(formality.go): introduce formality settings for language translation refactor: remove dragoman.go to refactor translation implementation feat(improve.go): add document improvement functionality with SEO optimization - Introduces `Improver` struct to enhance document content for engagement, clarity, and SEO. - Implements `Improve` method to process documents in chunks for scalability. - Utilizes parameters like formality, keywords, and language for tailored improvements. - Supports splitting documents into manageable chunks for individual enhancement. - Ensures structural integrity of documents by preserving formatting elements. feat(cli.go): restructure CLI options for translate and improve commands - Encapsulate translation-related options within a `Translate` struct and introduce a new `Improve` command with its own set of options. This change organizes the CLI options more logically, separating translation and improvement functionalities into distinct command groups for better user experience and code maintainability. - Replace `Rules` option with `Instructions` in both `Translate` and `Improve` commands to better reflect the purpose of providing guidance to the translation or improvement process. - Add `Formality`, `Keywords`, and `Language` options to the `Improve` command to support text improvement features, allowing users to specify the formality level, optimize for certain keywords, and set the language for the improvement process. - Modify the `Run` function to handle the new command structure, ensuring the application correctly processes commands based on the provided arguments and executes the appropriate functionality. - Implement `translate` and `improve` functions to encapsulate the logic for each command, improving code organization and making it easier to maintain and extend the application with new features in the future. refactor(cli.go): restructure output file creation to use nested options feat(cli.go): introduce `improve` function for document enhancement with OpenAI refactor(cli.go): update `getChunks` function to accept parameters directly for improved clarity and flexibility feat: add translation model and translator with tests - Implement a chat-based translation model interface and a function type to facilitate easy translation model creation. - Develop a Translator struct with methods to translate text documents, supporting chunk-based translation, preservation of specific terms, and custom translation instructions. - Include comprehensive unit tests to validate translation functionality, including handling of source and target languages, preservation of terms, and proper prompt generation based on translation parameters.
1 parent 9554e22 commit 83e2918

9 files changed

+529
-247
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
playground/**
12
*.exe
23
*.exe~
34
*.dll

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ human would understand (like 'English', 'German', 'French', etc.). If not
5555
provided, it defaults to 'auto', meaning the language is automatically detected.
5656

5757
```bash
58-
dragoman source.json --from English
58+
dragoman translate source.json --from English
5959
```
6060

6161
**`-t` or `--to`**
@@ -65,7 +65,7 @@ specified in any format that a human would understand (like 'English', 'German',
6565
'French', etc.). If not provided, it defaults to 'English'.
6666

6767
```bash
68-
dragoman source.json --to French
68+
dragoman translate source.json --to French
6969
```
7070

7171
**`-o` or `--out`**
@@ -74,7 +74,7 @@ The path to the output file where the translated content will be saved. If this
7474
option is not provided, the translated content will be printed to stdout.
7575

7676
```bash
77-
dragoman source.json --out target.json
77+
dragoman translate source.json --out target.json
7878
```
7979

8080
**`--split-chunks`**
@@ -85,7 +85,7 @@ with one of the provided prefixes will create a new chunk.
8585

8686
**Example: Split a Markdown file into chunks when encountering H2 and H3 headings:**
8787
```bash
88-
dragoman source.json --split-chunks "## " --split-chunks "### "
88+
dragoman translate source.json --split-chunks "## " --split-chunks "### "
8989
```
9090

9191
**`-u` or `--update`**
@@ -95,7 +95,7 @@ are missing in the output file. This option requires the source and output files
9595
to be JSON!
9696

9797
```bash
98-
dragoman source.json --out target.json --update
98+
dragoman translate source.json --out target.json --update
9999
```
100100

101101
#### Example
@@ -125,7 +125,7 @@ option to only translate the newly added fields and merge them into the output f
125125
```
126126

127127
```bash
128-
dragoman en.json --out de.json --update
128+
dragoman translate en.json --out de.json --update
129129
```
130130

131131
Result:
@@ -146,7 +146,7 @@ Result:
146146
This option allows you to specify a list of specific words or phrases, separated by commas, that you want to remain unchanged during the translation process. It's particularly useful for ensuring that certain terms, which may have significance in their original form or are used in specific contexts (like code, trademarks, or names), are not altered. These specified terms will be recognized and preserved whether they appear in isolation or as part of larger strings. This feature is especially handy for content that includes embedded terms within other elements, such as HTML tags. For instance, using --preserve ensures that a term like <span class="font-bold">Drago</span>man retains its original form post-translation. Note that the effectiveness of this feature may vary depending on the language model used, and it is optimized for use with OpenAI's GPT models.
147147

148148
```bash
149-
dragoman source.json --preserve Dragoman
149+
dragoman translate source.json --preserve Dragoman
150150
```
151151

152152
**`-v` or `--verbose`**
@@ -155,7 +155,7 @@ A flag that, if provided, makes the CLI provide more detailed output about the
155155
process and result of the translation.
156156

157157
```bash
158-
dragoman source.json --verbose
158+
dragoman translate source.json --verbose
159159
```
160160

161161
**`-h` or `--help`**

dragoman.go

-187
This file was deleted.

formality.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dragoman
2+
3+
const (
4+
// FormalityUnspecified indicates the absence of a specified formality level in
5+
// translation or language settings.
6+
FormalityUnspecified Formality = ""
7+
8+
// FormalityFormal represents the use of formal language and address forms,
9+
// applicable across all languages where such distinctions exist.
10+
FormalityFormal Formality = "formal"
11+
12+
// FormalityInformal specifies the use of informal language and address forms,
13+
// applicable across various languages where distinctions between formality
14+
// levels exist.
15+
FormalityInformal Formality = "informal"
16+
)
17+
18+
// Formality represents the level of formality in language, ranging from formal
19+
// to informal, providing contextual cues for language translation or usage. It
20+
// supports checking if a specific formality has been set and converts to its
21+
// string representation. Formality also guides language adjustments based on
22+
// the desired tone and social context.
23+
type Formality string
24+
25+
// IsSpecified reports whether a [Formality] instance has a specified value
26+
// other than the default unspecified state.
27+
func (f Formality) IsSpecified() bool {
28+
return f != FormalityUnspecified
29+
}
30+
31+
// String returns the string representation of the formal language setting
32+
// encapsulated by the [Formality] type.
33+
func (f Formality) String() string {
34+
return string(f)
35+
}
36+
37+
func (f Formality) instruction() string {
38+
if f == FormalityInformal {
39+
return "Use informal language and address forms, applicable across all languages where such distinctions exist."
40+
}
41+
if f == FormalityFormal {
42+
return "Use formal language and address forms, applicable across all languages where such distinctions exist."
43+
}
44+
return ""
45+
}

0 commit comments

Comments
 (0)