{"record":{"id":"6a5bed05001dab60","repo":"iflytek/astron-agent","slug":"api-requires-chinese-cn-as-either-source-or-target-language","errorCode":null,"errorMessage":"API requires Chinese (cn) as either source or target language. Current combination: {source_language} → {target_language} is not supported.","messagePattern":"API requires Chinese \\(cn\\) as either source or target language\\. Current combination: (.+?) → (.+?) is not supported\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"core/plugin/aitools/service/translation/translation_service.py","lineNumber":79,"sourceCode":"            )\n        return value\n\n    @field_validator(\"source_language\")\n    @classmethod\n    def validate_source_language(cls, value: str) -> str:\n        \"\"\"validate source language\"\"\"\n        if value not in VALID_LANGUAGE_CODES:\n            raise ValueError(\n                f\"Invalid source language: {value}.\\n\"\n                f\"Valid options: {list(VALID_LANGUAGE_CODES)}\"\n            )\n        return value\n\n    @model_validator(mode=\"after\")\n    def validate_language_combination(self) -> \"TranslationInput\":\n        \"\"\"Validate that at least one language is Chinese (cn)\"\"\"\n        if not is_valid_language_pair(self.source_language, self.target_language):\n            raise ValueError(\n                \"API requires Chinese (cn) as either source or target language. \"\n                f\"Current combination: {self.source_language} → {self.target_language} \"\n                \"is not supported.\"\n            )\n        return self\n\n\n@api_service(\n    method=\"POST\",\n    path=\"/aitools/v1/translation\",\n    query=None,\n    body=TranslationInput,\n    response=BaseResponse,\n    summary=\"Translate text from Chinese (cn) to other languages\",\n    description=\"Translate text from Chinese (cn) to other languages\",\n    tags=[\"public_cn\"],\n    deprecated=True,\n)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/service/translation/translation_service.py#L61-L97","documentation":"The `validate_language_combination` model_validator (mode=\"after\") enforces that at least one of source_language/target_language is Chinese (\"cn\"), because the underlying iFlytek translation API only supports pairs involving Chinese. `is_valid_language_pair` returning False triggers this ValueError, wrapped by pydantic into a ValidationError. The message shows the exact offending pair.","triggerScenarios":"Constructing TranslationInput with a pair like en→ja, fr→de, or any combination where neither side is \"cn\" — even when both codes are individually valid.","commonSituations":"Users pick two non-Chinese languages in the UI; generic translation clients reuse the endpoint for arbitrary pairs; routing all traffic to this API without checking pair support first.","solutions":["Route non-Chinese pairs to a different translation backend that supports them.","For a pair like en→ja, translate in two hops through Chinese (en→cn then cn→ja) if acceptable quality-wise.","Constrain the UI so target_language options depend on the chosen source (or vice versa) such that one side is always cn.","Check pair validity client-side with the same rule (source=='cn' || target=='cn') before calling."],"exampleFix":"// before\nawait translate({ text, source_language: 'en', target_language: 'ja' }); // rejected\n// after\nif (source !== 'cn' && target !== 'cn') {\n  const mid = await translate({ text, source_language: source, target_language: 'cn' });\n  return translate({ text: mid, source_language: 'cn', target_language: target });\n}\nreturn translate({ text, source_language: source, target_language: target });","handlingStrategy":"validation","validationCode":"function isSupportedPair(source, target) {\n  return source === 'cn' || target === 'cn';\n}","typeGuard":null,"tryCatchPattern":"try:\n    inp = TranslationInput(**payload)\nexcept ValidationError as e:\n    if 'Chinese (cn)' in str(e):\n        return error_response('该翻译接口要求源语言或目标语言为中文(cn)', 400)\n    raise","preventionTips":["Constrain UI options so one side is always Chinese, or offer a pivot-translation path for non-Chinese pairs.","Document the cn-involving-pair requirement wherever the endpoint is consumed.","Validate the pair client-side with the same rule as the model validator."],"tags":["validation","translation","language-pairs","unsupported"],"backgroundTag":"invalid-argument-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}