Detect the langauge of a string.
(text: str)
| 223 | |
| 224 | |
| 225 | def detect_language(text: str) -> str: |
| 226 | """Detect the langauge of a string.""" |
| 227 | import polyglot # pip3 install polyglot pyicu pycld2 |
| 228 | from polyglot.detect import Detector |
| 229 | from polyglot.detect.base import logger as polyglot_logger |
| 230 | import pycld2 |
| 231 | |
| 232 | polyglot_logger.setLevel("ERROR") |
| 233 | |
| 234 | try: |
| 235 | lang_code = Detector(text).language.name |
| 236 | except (pycld2.error, polyglot.detect.base.UnknownLanguage): |
| 237 | lang_code = "unknown" |
| 238 | return lang_code |
nothing calls this directly
no outgoing calls
no test coverage detected