🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

xtrans

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xtrans - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
+1
-1
dist/prompts/base-dictionary.js

@@ -132,3 +132,3 @@ import { TagStreamParser } from '../utils/tag-parser.js';

const originLabel = isChinese ? '词源' : 'Origin';
const idiomsLabel = isChinese ? '成语' : 'Idioms';
const idiomsLabel = isChinese ? '短语' : 'Idioms';
const examplesLabel = isChinese ? '示例' : 'Examples';

@@ -135,0 +135,0 @@ // Use ordered items if available (preserves LLM output order)

@@ -14,4 +14,6 @@ import { BaseDictionaryStrategy } from './base-dictionary.js';

- Grammar patterns: show how the word is used in structures (e.g. [T], [I], [+ to infinitive]).
- Common mistakes or usage notes for learners.
- Examples should use simple, natural English.
- Prefer the MOST COMMON modern meanings first; avoid archaic or rare senses.
- Common mistakes or usage notes for learners (keep brief).
- Avoid etymology, citations, and historical detail.
- Examples should be short, everyday, and learner-friendly in the source language.

@@ -21,3 +23,8 @@ CRITICAL INSTRUCTION:

- DO NOT use JSON.
- STRICTLY FOLLOW THE STRUCTURE BELOW.
- Omit any field you are not confident about.
- If the input is a phrase or sentence, prioritize meaning + example and skip etymology/phonetic/part-of-speech when not applicable.
- CEFR tags are optional; omit if unknown.
- FOLLOW THE STRUCTURE BELOW when the field is applicable.
- [WORD] MUST be exactly the user's input, verbatim (case and spacing preserved).
- [MEANING] MUST be written only in the target language. Do NOT include English unless the target language is English.

@@ -31,3 +38,3 @@ [WORD] The original source word ONLY

[MEANING] Simple, clear definition in target language. Use easy words to explain difficult ones.
[EXAMPLE] Natural example sentence with translation
[EXAMPLE] Natural example sentence plus its translation into the target language (omit translation if the source is already in the target language)
[END]

@@ -46,4 +53,4 @@

[POS] exclamation
[MEANING] 你好,用于见面时的问候或打电话时的开头语 (used when you meet someone or start a phone conversation)
[EXAMPLE] Hello, how are you? 你好,你怎么样?
[MEANING] Used when you meet someone or start a phone conversation (expressed in the target language)
[EXAMPLE] Hello, how are you? (translated into the target language)
[END]

@@ -53,4 +60,4 @@

[POS] noun [C]
[MEANING] 问候,打招呼 (something you say or do to greet someone)
[EXAMPLE] I said hello but she didn't answer. 我打了声招呼但她没回应。
[MEANING] Something you say or do to greet someone (expressed in the target language)
[EXAMPLE] I said hello but she didn't answer. (translated into the target language)
[END]

@@ -60,5 +67,5 @@

[SYNONYM] hey - very informal, used with friends
[IDIOM] say hello 打招呼
[IDIOM] say hello (translated into the target language)
`;
}
}

@@ -50,5 +50,7 @@ import { TagStreamParser } from '../utils/tag-parser.js';

4. Output specific tags for parsing.
5. Always include [CORRECT]. Omit [MISTAKE] or [IMPROVE] if you are not confident about them.
Required Tags:
[CORRECT] The corrected sentence(s)
Optional Tags:
[MISTAKE] Specific error explanation (one per line)

@@ -55,0 +57,0 @@ [IMPROVE] Optional suggestion for better style/tone (one per line)

@@ -5,3 +5,2 @@ import { CambridgePromptStrategy } from './cambridge.js';

import { TranslationPromptStrategy } from './translation.js';
import { YoudaoPromptStrategy } from './youdao.js';
const strategies = {

@@ -12,3 +11,2 @@ 'cambridge': new CambridgePromptStrategy(),

'translation': new TranslationPromptStrategy(),
'youdao': new YoudaoPromptStrategy(),
};

@@ -15,0 +13,0 @@ export const PromptFactory = {

@@ -12,6 +12,7 @@ import { BaseDictionaryStrategy } from './base-dictionary.js';

- Prefer British English pronunciation and spelling.
- Include DETAILED etymology tracing the word's origin through history.
- Include etymology when confident; otherwise omit.
- Usage labels: formal, informal, archaic, literary, technical, dated, etc.
- Definitions ordered HISTORICALLY (earliest meaning first, then derived meanings).
- Examples should include literary or historical citations where possible.
- Examples should include literary or historical citations when confident; otherwise provide a neutral but formal example.
- Avoid learner notes and CEFR labels.

@@ -21,3 +22,7 @@ CRITICAL INSTRUCTION:

- DO NOT use JSON.
- STRICTLY FOLLOW THE STRUCTURE BELOW.
- Omit any field you are not confident about.
- If the input is a phrase or sentence, prioritize meaning + example and skip etymology/phonetic/part-of-speech when not applicable.
- FOLLOW THE STRUCTURE BELOW when the field is applicable.
- [WORD] MUST be exactly the user's input, verbatim (case and spacing preserved).
- [MEANING] MUST be written only in the target language. Do NOT include English unless the target language is English.

@@ -30,4 +35,4 @@ [WORD] The original source word ONLY

[POS] Part of Speech (with formal labels: n., v., adj., adv., int., etc.)
[MEANING] Scholarly definition in target language with English clarification in parentheses
[EXAMPLE] Literary or historical citation with source attribution if possible
[MEANING] Scholarly definition in the target language only
[EXAMPLE] Literary or historical citation with source attribution when confident. Include a translation into the target language (omit translation if the source is already in the target language).
[END]

@@ -37,3 +42,3 @@

[ANTONYM] Antonym with register distinction - One per line
[ORIGIN] DETAILED etymology: Proto-language roots → Old/Middle English evolution → modern usage. Include dates of first attestation.
[ORIGIN] Etymology: Proto-language roots → Old/Middle English evolution → modern usage. Include dates only when confident.

@@ -48,4 +53,4 @@ Example Output:

[POS] int.
[MEANING] 用以打招呼或引起注意 (Used as a greeting or to attract attention)
[EXAMPLE] "Hello, old fellow!" — P.G. Wodehouse, 1915
[MEANING] Used as a greeting or to attract attention (expressed in the target language)
[EXAMPLE] "Hello, old fellow!" Provide the translation in the target language after the sentence. Include citation only if confident.
[END]

@@ -55,4 +60,4 @@

[POS] n.
[MEANING] 招呼,问候之语 (An utterance of 'hello'; a greeting)
[EXAMPLE] She called out a cheerful hello. 她愉快地打了声招呼。
[MEANING] An utterance of "hello"; a greeting (expressed in the target language)
[EXAMPLE] She called out a cheerful hello. (translated into the target language)
[END]

@@ -59,0 +64,0 @@

@@ -14,7 +14,9 @@ import { BaseDictionaryStrategy } from './base-dictionary.js';

- Format each field with a tag like [TAG] Content.
- Provide BILINGUAL content where appropriate (Source + Target).
- STRICTLY FOLLOW THE STRUCTURE BELOW.
- Provide bilingual examples where appropriate (Source + Target).
- Omit any field you are not confident about.
- If the input is a phrase or sentence, prioritize meaning + example and skip etymology/phonetic/part-of-speech when not applicable.
- FOLLOW THE STRUCTURE BELOW when the field is applicable.
- [WORD] MUST be exactly the user's input, verbatim (case and spacing preserved).
- [MEANING] MUST be written only in the target language. Do NOT include English unless the target language is English.
[SCHEMA] LAP/1.0
[MODE] translation
[WORD] The original source word ONLY

@@ -27,13 +29,11 @@ [PHONETIC] IPA phonetic transcription (UK/US if different)

[MEANING] Precise definition in target language. Order definitions by frequency.
[EXAMPLE] Bilingual example sentence showing common collocations.
[EXAMPLE] Example sentence plus its translation into the target language (omit translation if the source is already in the target language).
[END]
[SYNONYM] Synonyms with nuance - One per line (e.g. "hi (嗨) - Informal")
[ANTONYM] Antonyms with nuance - One per line (e.g. "bad (坏) - General")
[IDIOM] Common idioms/phrases containing the word - One per line (e.g. "say hello to (向...问好)")
[SYNONYM] Synonyms with nuance - One per line (e.g. "hi (target translation) - Informal")
[ANTONYM] Antonyms with nuance - One per line (e.g. "bad (target translation) - General")
[IDIOM] Common idioms/phrases containing the word - One per line (e.g. "say hello to (target translation)")
[ORIGIN] Rich etymology: Trace root -> development -> first use. (e.g. "From Old English hāl (whole) -> Middle English...")
Example Output:
[SCHEMA] LAP/1.0
[MODE] translation
[WORD] hello

@@ -47,4 +47,4 @@ [PHONETIC] /hɛˈloʊ/

[POS] interjection
[MEANING] 你好 (Used as a greeting or to begin a telephone conversation)
[EXAMPLE] Hello, Paul. (你好,保罗。)
[MEANING] A greeting used to begin a conversation (expressed in the target language)
[EXAMPLE] Hello, Paul. Provide the translation in the target language after the sentence.
[END]

@@ -54,10 +54,10 @@

[POS] noun
[MEANING] 招呼 (An utterance of 'hello'; a greeting)
[EXAMPLE] She said hello to me. (她向我打了个招呼。)
[MEANING] An utterance of "hello"; a greeting (expressed in the target language)
[EXAMPLE] She said hello to me. Provide the translation in the target language after the sentence.
[END]
[SYNONYM] hi (嗨) - Casual
[SYNONYM] greetings (问候) - Formal
[ANTONYM] goodbye (再见) - General
[IDIOM] say hello to (向...问好)
[SYNONYM] hi (translated into the target language) - Casual
[SYNONYM] greetings (translated into the target language) - Formal
[ANTONYM] goodbye (translated into the target language) - General
[IDIOM] say hello to (translated into the target language)
[ORIGIN] Mid 19th century: alteration of hollo; related to Old High German halā (hail).

@@ -64,0 +64,0 @@ `;

@@ -201,3 +201,2 @@ import { checkbox, confirm, input as inputPrompt, password, select } from '@inquirer/prompts';

{ name: 'Translation (通用翻译)', value: 'translation' },
{ name: 'Youdao (有道词典风格)', value: 'youdao' },
{ name: 'Oxford (牛津词典风格)', value: 'oxford' },

@@ -245,7 +244,33 @@ { name: 'Cambridge (剑桥词典风格)', value: 'cambridge' },

try {
lang = await inputPrompt({
default: configService.getTargetLang(),
message: 'Enter target language:',
validate: (value) => value.length > 0 || 'Language code is required',
const current = configService.getTargetLang();
const customValue = '__custom__';
const popularChoices = [
{ name: 'English (en)', value: 'en' },
{ name: '中文 (zh)', value: 'zh' },
{ name: '日本語 (ja)', value: 'ja' },
{ name: '한국어 (ko)', value: 'ko' },
{ name: 'Español (es)', value: 'es' },
{ name: 'Français (fr)', value: 'fr' },
{ name: 'Deutsch (de)', value: 'de' },
{ name: 'Русский (ru)', value: 'ru' },
];
const defaultValue = popularChoices.some(choice => choice.value === current)
? current
: customValue;
const selected = await select({
choices: [
...popularChoices,
{ name: 'Custom... (输入自定义)', value: customValue },
],
default: defaultValue,
message: 'Select target language:',
pageSize: 10,
});
lang = selected === customValue
? await inputPrompt({
default: current,
message: 'Enter target language:',
validate: (value) => value.length > 0 || 'Language code is required',
})
: selected;
}

@@ -252,0 +277,0 @@ catch {

@@ -31,3 +31,3 @@ {

},
"version": "1.2.0"
"version": "1.2.1"
}
{
"name": "xtrans",
"description": "Minimalist AI-powered terminal translator / 极简 AI 终端翻译工具",
"version": "1.2.0",
"version": "1.2.1",
"author": "wengqianshan",

@@ -6,0 +6,0 @@ "bin": {

@@ -14,3 +14,3 @@ # xtrans

- 🔒 **本地模型支持**: 完美支持 **Ollama** 和 **LM Studio**。无需联网,保护隐私。
- 🔒 **本地模型支持**: 原生支持 **Ollama** 和 **LM Studio**。无需联网,保护隐私。
- 🌍 **多服务商**: 内置 **OpenAI**, **DeepSeek**, **Kimi (Moonshot)** 以及 **Ollama/LM Studio** 支持。

@@ -36,3 +36,3 @@ - 🛠 **高度可扩展**: 轻松添加任何兼容 **OpenAI 格式** 的 API 服务。

### 1. 快速翻译
使用别名 `t` (或 `xtrans`) 进行即时翻译。
全局安装后,可直接使用 `t` 或 `xtrans` 进行即时翻译;使用 npx 时请用 `xtrans`。

@@ -56,7 +56,7 @@ ```bash

### 2. 交互模式 (REPL)
不带参数运行即可进入交互式 shell。支持上下键 (↑/↓) 切换历史记录。
不带参数运行即可进入交互式 shell(全局安装可用 `t` 或 `xtrans`;npx 请用 `xtrans`)。支持上下键 (↑/↓) 切换历史记录。
```bash
xtrans
# Welcome to xtrans v1.0.0
t
# Welcome to xtrans v1.2.0
# Provider: ollama | Model: llama3 | Target: zh

@@ -66,2 +66,9 @@ # ›

#### 可用模式
在 REPL 内使用 `/mode` 切换,例如:`t /mode cambridge`。
- `translation`: 通用翻译
- `cambridge`: 剑桥词典风格(学习者友好)
- `oxford`: 牛津词典风格(学术/历史)
- `grammar`: 语法检查
### 3. 管理命令

@@ -73,2 +80,3 @@ 你可以在交互模式内 (输入 `/`) 或直接从终端运行这些命令。

| `/use` | 切换服务商或模型 (交互式) | `t /use` |
| `/mode` | 切换模式 (translation/cambridge/oxford/grammar) | `t /mode oxford` |
| `/target` | 设置目标语言 | `t /target ja` |

@@ -75,0 +83,0 @@ | `/status` | 检查服务状态及当前模型 | `t /status` |

import { BaseDictionaryStrategy } from './base-dictionary.js';
export declare class YoudaoPromptStrategy extends BaseDictionaryStrategy {
id: string;
getSystemMessage(targetLang: string): string;
}
import { BaseDictionaryStrategy } from './base-dictionary.js';
export class YoudaoPromptStrategy extends BaseDictionaryStrategy {
id = 'youdao';
getSystemMessage(targetLang) {
return `
You are simulating Youdao Dictionary (有道词典), the most popular Chinese-English dictionary.
Provide a Youdao-style entry for the user input. Translate into "${targetLang}".
Style Guidelines:
- Prioritize PRACTICAL, everyday usage over academic precision.
- Show CONCISE Chinese translations first, then brief English explanations.
- Include internet slang, colloquial usage, and modern expressions where relevant.
- Examples should be short, practical sentences from daily life.
- Keep definitions compact: focus on the most common 2-3 meanings.
CRITICAL INSTRUCTION:
- Response MUST be a stream of data lines using tags.
- DO NOT use JSON.
- STRICTLY FOLLOW THE STRUCTURE BELOW.
[WORD] The original source word ONLY
[PHONETIC] IPA phonetic transcription
[TAG] Usage frequency or domain tags (e.g. "CET4", "Daily", "Internet", "Business"). One per line.
[BLOCK:DEF]
[POS] Part of Speech
[MEANING] Concise translation in target language (keep it short, like "你好;喂")
[EXAMPLE] Short practical example with translation
[END]
[SYNONYM] Synonym - One per line
[IDIOM] Common phrase or collocation - One per line
Example Output:
[WORD] hello
[PHONETIC] /hɛˈloʊ/
[TAG] CET4
[TAG] Daily
[BLOCK:DEF]
[POS] int.
[MEANING] 你好;喂(用于问候或打电话)
[EXAMPLE] Hello! How are you? 你好!你怎么样?
[END]
[BLOCK:DEF]
[POS] n.
[MEANING] 招呼;问候
[EXAMPLE] She gave me a friendly hello. 她友好地跟我打了个招呼。
[END]
[SYNONYM] hi - 口语常用
[SYNONYM] hey - 非正式
[IDIOM] say hello to 向…问好
[IDIOM] hello world 你好世界(编程术语)
`;
}
}