DeepL Free API (No TOKEN required)
Go to file
Vincent Young 0dd935ba7e
feat(translate): validate source/target language codes
Previously TranslateByDeepLX silently mapped any caller-supplied code
through toOneshotLang(), falling back to a lowercased pass-through for
unknown codes. The oneshot endpoint accepts unknown codes with a 200
but echoes the source text back untranslated, leaving callers to
distinguish "translated, identical to source" from "language not
supported" without a clear signal.

Validate strictly against the language table the extension bundles in
background.js (array `y` for target-capable codes, `A` for the
source-only EN / PT aliases) and return HTTP 400 with a list of
supported codes on mismatch. This also catches:

  - target_lang = ""        → "target_lang is required"
  - target_lang = "auto"    → "target_lang cannot be \"auto\"; pick one of: ..."
  - source_lang = ""/"auto" → allowed, server autodetects
  - case-insensitive       → strings.ToUpper before lookup

Pick up languages the previous map missed:

  + ES-419 (Latin American Spanish)
  + HE     (Hebrew)
  + VI     (Vietnamese)

Fix the EN / PT source-lang mapping: the extension's `A` array maps
both to the generic langCodeForIta ("en"/"pt"), not the regional
default. As a target they continue to resolve to en-US / pt-BR for
backward compat with callers that historically passed "EN" / "PT".

Verified end-to-end:
  - 5 valid codes (DE, ZH-HANT, HE, VI, ES-419) → 200 + translated text
  - Invalid target "XX"  → 400, message lists 38 supported codes
  - Invalid source "ZZ"  → 400, message lists 38 codes + "auto"
  - target_lang "auto"   → 400
  - source autodetect (empty / "auto") + valid target → 200
  - Lowercase input "de" → 200 (case-insensitive)
2026-05-22 12:12:27 +08:00
.github chore: bump Go version to 1.24.2 in Dockerfile, go.mod, and CI workflows 2025-04-08 14:27:01 -04:00
img docs: add img 2024-03-02 02:47:18 -05:00
service refactor: make service exportable (#183) 2025-04-08 13:53:20 -04:00
translate feat(translate): validate source/target language codes 2026-05-22 12:12:27 +08:00
.cross_compile.sh ci: fix compile error 2024-03-20 16:52:54 -04:00
.gitignore chore: add gitignore 2023-07-01 21:31:38 +08:00
compose.yaml Update compose.yaml 2024-12-22 14:18:30 -05:00
deeplx.service Update deeplx.service 2023-02-18 20:55:20 +08:00
Dockerfile Update Dockerfile to use Go 1.25 base image (#215) 2026-03-18 03:47:26 -07:00
go.mod feat(translate): migrate to oneshot endpoint (#217) 2026-05-22 12:04:44 +08:00
go.sum feat(translate): migrate to oneshot endpoint (#217) 2026-05-22 12:04:44 +08:00
install.sh Update install.sh 2023-02-18 20:57:58 +08:00
LICENSE Create LICENSE 2022-10-20 02:12:18 +08:00
main.go refactor: make service exportable (#183) 2025-04-08 13:53:20 -04:00
me.missuo.deeplx.plist Update README.md 2022-10-20 02:11:14 +08:00
README.md docs: remove icon 2024-11-30 19:56:38 -05:00
uninstall.sh feat(uninstall): Add DeepLX uninstallation script (#203) 2025-08-26 20:34:10 +08:00

GitHub Workflow Go Version Go Report GitHub License Docker Pulls Releases

How to use

!TIP]

Learn more about [📘 Using DeepLX](https://deeplx.owo.network) by checking it out.

Discussion Group

Telegram Group

Acknowledgements

Contributors

Activity

Alt

License

FOSSA Status