Skip to content

Commit f4cf153

Browse files
committed
feat(auto-translate): init translate cli wrapper
1 parent 79dac4d commit f4cf153

6 files changed

Lines changed: 117 additions & 0 deletions

File tree

bun.lockb

5.89 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"@shikijs/vitepress-twoslash": "^1.5.2",
88
"@types/bun": "latest",
99
"@types/node": "^20.12.12",
10+
"chatgpt-md-translator": "^1.7.1",
1011
"ts-odata-client": "2.0.2",
1112
"vitepress": "^1.1.4",
1213
"vue": "^3.4.27"

scripts/input.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Prompt
2+
3+
This page is special page that collect the prompt from generative AI for example GPT-3, GPT-4, etc. The prompt is used to generate the content for the page.
4+
5+
## Localization Prompt List
6+
- [Thai Prompt](./th/prompt.md)

scripts/output.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# หัวข้อ
2+
3+
หน้านี้เป็นหน้าพิเศษที่รวบรวมข้อความโดยใช้เทคโนโลยี AI ที่สร้างข้อความเช่น GPT-3, GPT-4 เป็นต้น โดยข้อความที่ใช้เป็นข้อความเริ่มต้นสำหรับสร้างเนื้อหาของหน้านี้
4+
5+
## รายการข้อความเริ่มต้นในภาษาไทย
6+
- [ข้อความเริ่มต้นภาษาไทย](./th/prompt.md)

scripts/prompt.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
แปลไทยโดยมีเงื่อนไขดังนี้
2+
3+
- การเลือกใช้คำภาษาไทย
4+
- คำว่า `ฉัน` ให้ใช้คำว่า `ผม` แทน
5+
- คำว่า `ของตน` ให้ใช้คำว่า `ของตัวเอง` แทน
6+
- คำว่า `การอนุมาน` ให้ใช้คำว่า `การคาดเดา` แทน
7+
- การเลือกคำแปลจาก ภาษาอังกฤษเป็นภาษาไทย โดยที่ถ้าพูดถึงคำนั้นครั้งแรกของเอกสารที่แปลทั้งหมด ให้ใส่วงเล็บเพื่อใส่ภาษาอังกฤษที่เป็นคำเดิมไว้ด้วย
8+
- คำว่า `Type-safe` ให้แปลว่า `ชนิดข้อมูลแบบปลอดภัย`
9+
- คำว่า `Best Practice` ให้แปลว่า `แนวปฏิบัติที่ดีนำไปใช้งานได้จริง`
10+
- คำว่า `Design Pattern` ให้แปลว่า `แนวทางการออกแบบ`
11+
- คำว่า `Modular` ให้แปลว่า `โมดูล`
12+
- คำว่า `Inline Types` ให้แปลว่า `ชนิดข้อมูลแบบใกล้เคียง`
13+
- คำว่า `Shared Types` ให้แปลว่า `ชนิดข้อมูลที่ใช้ร่วมกัน`
14+
- คำว่า `Common/Global Types` ให้แปลว่า `ชนิดข้อมูลทั่วไป/ใช้ร่วมกันทั้งโปรเจกต์`
15+
- คำว่า `global declarations` ให้แปลว่า `การประกาศสำหรับใช้ร่วมกันทั้งโปรเจกต์`
16+
- คำว่า `global types` ให้แปลว่า `ชนิดข้อมูลสำหรับใช้ร่วมกันทั้งโปรเจกต์`
17+
- คำว่า `third-party libraries` ให้แปลว่า `ไลบรารีที่ติดตั้งจากภายนอก`
18+
- คำว่า `built-in types` ให้แปลว่า `ชนิดข้อมูลที่มีมาให้ใช้งานเริ่มต้น`
19+
- คำที่ไม่ต้องการให้มีวงเล็บภาษาอังกฤษที่เป็นคำเดิม
20+
- `Example`
21+
- `Error`
22+
- `Contributing`
23+
- `Glossary`
24+
- การเลือกคำแปลจาก ภาษาอังกฤษเป็นภาษาไทย
25+
- คำว่า `Modern` ให้แปลว่า `สมัยใหม่`
26+
- คำว่า `Prerequisites` ให้แปลว่า `สิ่งที่ควรเรียนรู้มาก่อน`
27+
- คำว่า `Recommended Reading` ให้แปลว่า `หนังสือและเอกสารที่แนะนำให้อ่าน`
28+
- คำว่า `Disclaimer` ให้แปลว่า `คำชี้แจงที่สำคัญ`
29+
- คำว่า `open an issue ... on Github` ให้แปลว่า `เปิด Issue ... บน Github`
30+
- คำว่า `Traditional Type` ให้แปลว่า `การประกาศชนิดข้อมูลแบบดั้งเดิม`
31+
- คำว่า `type inference` ให้แปลว่า `การคาดเดาชนิดข้อมูล`
32+
- คำว่า `type system` ให้แปลว่า `ระบบชนิดข้อมูล`
33+
- คำว่า `definition of types` หรือ `type definition` ให้แปลว่า `การประกาศชนิดข้อมูล`
34+
- คำว่า `Let's break down` ให้แปลว่า `ลองพยายามอธิบาย`
35+
- คำว่า `Type loosing` ให้แปลว่า `การทำให้ชนิดข้อมูลหลวมลง`
36+
- คำว่า `Type tightening` ให้แปลว่า `การทำให้ชนิดข้อมูลเข้มข้นขึ้น`
37+
- คำว่า `codebase` ให้แปลว่า `โค้ด`
38+
- คำว่า `TypeScript Libraries` ให้แปลว่า `ไลบรารี TypeScript`
39+
- คำว่า `Glossary` ให้แปลว่า `คลังคำศัพท์`
40+
- คำว่า `Project` ให้แปลว่า `โปรเจกต์`
41+
- คำว่า `catch ... errors` ให้แปลว่า `เจอ ... ข้อผิดพลาด`
42+
- คำว่า `data interfaces` ให้แปลว่า `interface ของข้อมูล`
43+
- การเลือกคำคำที่มีบริบทข้างเคียง ซึ่งแต่ละที่อาจจะแปลไม่เหมือนกัน
44+
- คำว่า `Type` อาจจะแปลว่า `ชนิดข้อมูล` หรือ `ประเภท` ให้พิจารณาจากบริบทข้างเคียง
45+
- คำที่ไม่ต้องการแปล
46+
- `Pull Request`
47+
- `Libraries`
48+
- `E-book`
49+
- `business logic`
50+
- `Domain`

scripts/translate.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export interface ChatGptMarkdownTranslatorOptions {
2+
/**
3+
* Model (`MODEL_NAME`)
4+
5+
This is the setting that has the greatest impact on translation accuracy (and price!). Set this to one of the [Chat models](https://platform.openai.com/docs/models/) accepted by the OpenAI API.
6+
7+
```markdown
8+
- Recommended:
9+
- `gpt-4-turbo` (or using shortcut `4`)
10+
- `gpt-3.5-turbo` (or using shortcut `3`)
11+
- Legacy / No longer recommended:
12+
- `gpt-4`
13+
- `gpt-4-32k` (or using shortcut `4large`)
14+
- `gpt-3.5-turbo-16k` (or using shortcut `3large`)
15+
```
16+
17+
Shortcuts (in brackets) are available. Starting from v1.7.0, the shortcut `4` points to `gpt-4-turbo` rather than `gpt-4`.
18+
19+
Although GPT-4 is much smarter, it is slower and much more expensive than GPT-3. Try using the GPT-3 model first, especially while you are experimenting with this tool. It's recommended to set the usage limit to a reasonable amount (e.g., $10) on the OpenAI's account management page.
20+
*/
21+
model?: "3" | "4" | "gpt-3.5-turbo" | "gpt-4o";
22+
inputPath: string;
23+
outputPath: string;
24+
cwd?: string;
25+
}
26+
27+
async function chatGptMarkdownTranslator(options: ChatGptMarkdownTranslatorOptions) {
28+
console.log(
29+
`Starting translation with input file: "${options.inputPath}" and output file: "${options.outputPath}"...`
30+
);
31+
32+
const model = options.model ?? "gpt-3.5-turbo";
33+
console.log(`Translation starting with model: "${model}"...`);
34+
console.log('Env: ', process.env.OPENAI_API_KEY)
35+
Bun.spawn(
36+
["node_modules/.bin/chatgpt-md-translator", "--model", model, "--out", options.outputPath, options.inputPath],
37+
{
38+
cwd: options.cwd,
39+
env: { ...process.env }, // specify environment variables
40+
onExit(proc, exitCode, signalCode, error) {
41+
// exit handler
42+
},
43+
stdout: "inherit",
44+
}
45+
);
46+
console.log(`Translation completed`);
47+
}
48+
49+
await chatGptMarkdownTranslator({
50+
model: "gpt-3.5-turbo",
51+
inputPath: `./input.md`,
52+
outputPath: `./output.md`,
53+
cwd: import.meta.dirname,
54+
});

0 commit comments

Comments
 (0)