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
2024-03-02 02:47:18 -05:00
2024-03-20 16:52:54 -04:00
2023-07-01 21:31:38 +08:00
2024-12-22 14:18:30 -05:00
2023-02-18 20:55:20 +08:00
2023-02-18 20:57:58 +08:00
2022-10-20 02:12:18 +08:00
2022-10-20 02:11:14 +08:00
2024-11-30 19:56:38 -05:00

GitHub Workflow Go Version Go Report GitHub License Docker Pulls Releases

How to use

[!TIP]

Learn more about 📘 Using DeepLX by checking it out.

Discussion Group

Telegram Group

Acknowledgements

Contributors

Activity

Alt

License

FOSSA Status

S
Description
DeepL Free API (No TOKEN required)
Readme MIT
1.5 MiB
Languages
Go 94.7%
Shell 4.7%
Dockerfile 0.6%