Skip to content

Add translator extension#27442

Open
Flartiny wants to merge 2 commits intoraycast:mainfrom
Flartiny:ext/translator
Open

Add translator extension#27442
Flartiny wants to merge 2 commits intoraycast:mainfrom
Flartiny:ext/translator

Conversation

@Flartiny
Copy link
Copy Markdown

@Flartiny Flartiny commented Apr 26, 2026

Description

This PR adds a new Raycast extension: Translator (Windows), focused on fast AI translation between Chinese,
Japanese, and English
.

Included Commands

  • Translator: translate manually entered text
  • Clipboard Translator: prefill text from clipboard and translate quickly
  • Translator Profiles: manage multiple API profiles (create/edit/duplicate/enable/disable/set default)

Screencast

PixPin_2026-04-26_18-33-11.mp4

Checklist

@raycastbot raycastbot added the new extension Label for PRs with new extensions label Apr 26, 2026
@raycastbot
Copy link
Copy Markdown
Collaborator

Congratulations on your new Raycast extension! 🚀

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days.

Once the PR is approved and merged, the extension will be available on our Store.

@Flartiny Flartiny marked this pull request as ready for review April 26, 2026 10:37
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

This PR adds a new Translator extension for Windows that supports AI-powered translation between Chinese, Japanese, and English via any OpenAI-compatible API. It includes three commands — manual translation, clipboard translation, and a profile manager with fallback routing — all implemented with well-structured hooks, typed error handling, and streaming SSE support.

The main issues are all P2: a manually defined CommandPreferences interface (should be auto-generated), dead-code placeholder replacements in prompt-builder.ts carried over from another project, a default target language assignment that routes Japanese input to Chinese (rather than English), and a category of "Communication" that arguably fits "Productivity" better.

Confidence Score: 4/5

Safe to merge after addressing the P2 findings; no blocking logic errors or security issues found

All findings are P2: a manually defined preferences interface, dead code in the prompt builder, a potentially surprising default language fallback, and a category mismatch. None affect runtime correctness or security.

src/types/profile.ts (manual Preferences type) and src/services/prompt-builder.ts (dead-code function)

Important Files Changed

Filename Overview
extensions/translator/src/types/profile.ts Defines CommandPreferences manually — should be auto-generated via raycast-env.d.ts instead
extensions/translator/src/services/prompt-builder.ts Contains dead-code clearNonTextPlaceholders function that replaces placeholders not present in the template
extensions/translator/src/services/language.ts Regex-based language detection; inferDefaultTargetLanguage silently routes Japanese source to Chinese target rather than English
extensions/translator/src/services/translator-client.ts Well-structured OpenAI-compatible HTTP client with streaming SSE parsing, inactivity timeout, and typed error classification
extensions/translator/src/services/translation-dispatcher.ts Implements profile-ordered fallback dispatch; correctly distinguishes recoverable vs. non-recoverable errors
extensions/translator/src/services/profile-store.ts Robust LocalStorage-backed profile store with validation, normalization, and safe JSON parsing
extensions/translator/src/translator-command.tsx Core command with well-decomposed hooks for clipboard prefill, language resolution, and translation submission
extensions/translator/package.json Valid schema, $schema present, Windows-only platform; category Communication is arguably a mismatch for a translation tool
extensions/translator/src/components/profile-editor-form.tsx Uses @raycast/utils useForm correctly with field-level validation; Form.PasswordField used for API key
extensions/translator/src/components/translator-views.tsx Clean view components for form, result, and error states; correctly integrates launchCommand for profile management
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/translator/src/types/profile.ts
Line: 18-20

Comment:
**Manually defined `CommandPreferences` interface**

`CommandPreferences` is manually defined here and passed to `getPreferenceValues<CommandPreferences>()` in `translator-command.tsx`. Per Raycast convention, preference types are auto-generated into `raycast-env.d.ts` when the extension runs — manually defining them creates a risk of the type going out of sync with `package.json` preferences. Remove this interface and use `getPreferenceValues<Preferences>()` with the auto-generated type instead.

**Rule Used:** What: Don't manually define `Preferences` for `get... ([source](https://app.greptile.com/review/custom-context?memory=d93fc9fb-a45d-4479-a6a4-b1b4af98ebc8))

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/translator/src/services/prompt-builder.ts
Line: 16-22

Comment:
**Dead-code placeholder replacements**

`clearNonTextPlaceholders` replaces `{{title_prompt}}`, `{{summary_prompt}}`, `{{terms_prompt}}`, and `{{imt_style_guide}}` — none of which appear in `PROMPT_TEMPLATE`. These `replaceAll` calls are no-ops and the function appears to be a leftover from another project's template. The entire function (and its call on line 28) can be removed without changing behavior.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/translator/src/services/language.ts
Line: 38-46

Comment:
**Japanese source always targets Chinese, never English**

When the detected source language is `ja`, `inferDefaultTargetLanguage` returns `zh`. Only the `zh``en` path is explicit; every other language (including `en` and `ja`) falls through to `zh`. A Japanese-speaking user who writes in Japanese and expects an English translation will silently receive a Chinese target instead. Consider adding an explicit `ja``en` branch if English is the intended default for Japanese input.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/translator/package.json
Line: 133-135

Comment:
**Category may be a mismatch**

`"Communication"` is defined for messaging, status, and collaboration tools. A text translation utility fits more naturally under `"Productivity"` (personal productivity tools). Consider updating the category.

```suggestion
  "categories": [
    "Productivity"
  ]
```

**Rule Used:** What: Assign at least one predefined category to e... ([source](https://app.greptile.com/review/custom-context?memory=f49debbf-b6f6-4c0d-9b35-e1927815992b))

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Add translator extension" | Re-trigger Greptile

Comment thread extensions/translator/src/types/profile.ts Outdated
Comment thread extensions/translator/src/services/prompt-builder.ts Outdated
Comment on lines +38 to +46
export function inferDefaultTargetLanguage(
sourceLanguage: SupportedLanguage,
): SupportedLanguage {
if (sourceLanguage === "zh") {
return "en";
}

return "zh";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Japanese source always targets Chinese, never English

When the detected source language is ja, inferDefaultTargetLanguage returns zh. Only the zhen path is explicit; every other language (including en and ja) falls through to zh. A Japanese-speaking user who writes in Japanese and expects an English translation will silently receive a Chinese target instead. Consider adding an explicit jaen branch if English is the intended default for Japanese input.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/translator/src/services/language.ts
Line: 38-46

Comment:
**Japanese source always targets Chinese, never English**

When the detected source language is `ja`, `inferDefaultTargetLanguage` returns `zh`. Only the `zh``en` path is explicit; every other language (including `en` and `ja`) falls through to `zh`. A Japanese-speaking user who writes in Japanese and expects an English translation will silently receive a Chinese target instead. Consider adding an explicit `ja``en` branch if English is the intended default for Japanese input.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is intentional for this extension

Comment thread extensions/translator/package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new extension Label for PRs with new extensions platform: Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants