{"record":{"id":"7be23e912c08153d","repo":"hankcs/HanLP","slug":"no-translation-for-lang-please-contribute-to-ou","errorCode":null,"errorMessage":"No translation for {lang}. Please contribute to our translation at https://github.com/hankcs/HanLP","messagePattern":"No translation for (.+?)\\. Please contribute to our translation at https://github\\.com/hankcs/HanLP","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"plugins/hanlp_common/hanlp_common/document.py","lineNumber":456,"sourceCode":"        .. Attention:: Note that the translated document might not print well in terminal due to non-ASCII characters.\n\n        Args:\n            lang: Target language to be translated to.\n            tok: Token key.\n            pos: Part-of-speech key.\n            dep: Dependency parse tree key.\n            sdp: Semantic dependency tree/graph key. SDP visualization has not been implemented yet.\n            ner: Named entity key.\n            srl: Semantic role labeling key.\n\n        Returns:\n            The translated document.\n\n        \"\"\"\n        if lang == 'zh':\n            from hanlp.utils.lang.zh import localization\n        else:\n            raise NotImplementedError(f'No translation for {lang}. '\n                                      f'Please contribute to our translation at https://github.com/hankcs/HanLP')\n        flat = isinstance(self[tok][0], str)\n        for task, name in zip(['pos', 'ner', 'dep', 'sdp', 'srl'], [pos, ner, dep, sdp, srl]):\n            annotations = self.get(name, None)\n            if not annotations:\n                continue\n            if flat:\n                annotations = [annotations]\n            translate: dict = getattr(localization, name, None)\n            if not translate:\n                continue\n            for anno_per_sent in annotations:\n                for i, v in enumerate(anno_per_sent):\n                    if task == 'ner' or task == 'dep':\n                        v[1] = translate.get(v[1], v[1])\n                    else:\n                        anno_per_sent[i] = translate.get(v, v)\n        return self","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/document.py#L438-L474","documentation":"Document.translate only has localized templates for Chinese ('zh'); requesting any other language raises NotImplementedError asking for community contributions.","triggerScenarios":"Calling doc.translate('en'), doc.translate(lang='ja'), or any lang != 'zh' on a Document object produced by HanLP parsing.","commonSituations":"Non-Chinese-speaking users wanting English output of pretty-printed annotations; passing a language code the API gives no hint about supporting.","solutions":["Call translate('zh') (or omit lang) to get the Chinese translation","Fork/contribute a localization module under hanlp.utils.lang.<lang> as the message suggests","Render the document without translation (to_markdown/pretty print uses raw field names)"],"exampleFix":"# before\ndoc.translate('en')  # NotImplementedError\n# after\ndoc.translate('zh')","handlingStrategy":"try-catch","validationCode":"SUPPORTED_TRANSLATE = {'zh'}\nif lang not in SUPPORTED_TRANSLATE:\n    lang = 'zh'","typeGuard":"def translate_supported(lang: str) -> bool:\n    return lang == 'zh'","tryCatchPattern":"try:\n    doc.translate(lang)\nexcept NotImplementedError:\n    doc.translate('zh')","preventionTips":["Only 'zh' is supported; don't expose lang switches to users without a whitelist"],"tags":["localization","document","not-implemented"],"backgroundTag":"unsupported-locale","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}