Skip to content

feat: Add local proxy support for translation requests#1142

Open
acefeng wants to merge 2 commits intotisfeng:devfrom
acefeng:feature/add-local-proxy
Open

feat: Add local proxy support for translation requests#1142
acefeng wants to merge 2 commits intotisfeng:devfrom
acefeng:feature/add-local-proxy

Conversation

@acefeng
Copy link
Copy Markdown

@acefeng acefeng commented Apr 9, 2026

feat: Add local proxy support for translation requests

Summary

Adds a Local Proxy configuration option under Settings → Advanced, allowing users to route all translation service requests through a custom HTTP or SOCKS5 proxy. This eliminates the need to configure system-wide proxy or third-party tools just to make individual translation services reachable.


Motivation

This feature has been requested multiple times across several issues:

The common scenario: many users run proxy software in rule-based or browser-only mode and don't enable a system-wide proxy. Without this feature, translation services that require a proxy would time out, forcing users to switch to global mode just for Easydict.


What's Changed

New UI — Settings → Advanced → Local Proxy

A new Local Proxy section is added below the existing HTTP Server section in the Advanced settings tab. Users can input a proxy URL; leaving it empty disables the proxy and falls back to system default networking.

![screenshot placeholder]

Supported proxy formats:

  • http://host:port — HTTP proxy (also tunnels HTTPS via CONNECT)
  • socks5://host:port — SOCKS5 proxy
  • host:port — treated as HTTP proxy

Key implementation details:

  • NetworkSession.swift (new): A final class NetworkSession singleton manages the app-wide Alamofire Session. It observes Defaults[.httpProxyURL] via Defaults.publisher and rebuilds the session immediately whenever the value changes — no app restart required.
  • A global computed variable EAF: Alamofire.Session is exposed at file scope, providing a drop-in replacement for Alamofire's built-in AF.
  • All 15 translation service files (GoogleService, BingService, DeepLService, BaiduService, YoudaoService, TencentService, CaiyunService, VolcanoService, AliService, NiuTransService, OllamaService, etc.) have been updated to use EAF instead of AF, so every request automatically respects the proxy setting.
  • A new Defaults.Keys.httpProxyURL key (default: empty string) is added to Defaults.Keys+Extension.swift.
  • Localization keys added for all supported languages (English, Simplified Chinese, Traditional Chinese, Slovak).

Files Changed

File Change
NetworkSession.swift New — proxy-aware session manager + global EAF accessor
Defaults.Keys+Extension.swift Added httpProxyURL key
AdvancedTab.swift Added Local Proxy section + @Default(.httpProxyURL)
Localizable.xcstrings Added 4 new localization keys
project.pbxproj Registered NetworkSession.swift
15 translation service files AFEAF

Testing

  1. Enter a non-existent local proxy (e.g. http://127.0.0.1:19999) → translation requests should fail with a connection error, confirming requests go through the proxy.
  2. Clear the field → requests recover immediately, confirming fallback to system default.
  3. Enter a valid local proxy port (e.g. http://127.0.0.1:7890 for Clash) with system proxy disabled → translation services that previously timed out should now work.

Closes #557
Related: #18, #688, #756

Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello acefeng, Thank you for your first PR contribution 🎉 acefeng

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a1e3845e6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Easydict/Swift/Utility/NetworkSession.swift
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea17e0981e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Easydict/Swift/Utility/NetworkSession.swift
@MoonMao42
Copy link
Copy Markdown
Contributor

On Easydict/Swift/Service/OpenAI/BaseOpenAIService.swift:78:

OpenAI(apiToken:) uses URLSession.shared, so NetworkSession.shared.urlSession never reaches this path.

        let openAI = OpenAI(
            configuration: .init(token: apiKey),
            session: NetworkSession.shared.urlSession
        )

Does this work?

@acefeng
Copy link
Copy Markdown
Author

acefeng commented Apr 16, 2026

On Easydict/Swift/Service/OpenAI/BaseOpenAIService.swift:78:

OpenAI(apiToken:) uses URLSession.shared, so NetworkSession.shared.urlSession never reaches this path.

        let openAI = OpenAI(
            configuration: .init(token: apiKey),
            session: NetworkSession.shared.urlSession
        )

Does this work?

Perhaps I should modify the description. open AI and gemini AI are not supported for the time being. open AI needs to modify the injection method, but for gemini AI, no injection method has been seen for the time being, so neither of them has been done for the time being

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

能否为软件加入内置代理

2 participants