Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] Tesseract checks function doesn't recognize Chinese language (and some other languages) correctly
### Description

Good morning, I am new user of paperless-ngx. I tried to start a container using the lazy installation scripts.
`bash -c "$(curl -L https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/install-paperless-ngx.sh)"`

**1. Problem Description**: when I set `PAPERLESS_OCR_LANGUAGE=eng+chi-sim`, the webserver cannot start correctly because it fails the tesseract language checks.

**2. Reason of the problem**: 
In `docker/docker-entrypoint.sh`, the tesseract language packages are installed through the following command: `pkg="tesseract-ocr-$lang"`. And the naming could be found in [Ubuntu tesseract-ocr-all](https://packages.ubuntu.com/focal/tesseract-ocr-all) for example. So to install the Chinese Simplified package, you need to specify `chi-sim` in `PAPERLESS_OCR_LANGUAGES`.

However, when `-ngx` checks if the tesseract language package exists, it calls `tesseract --list-langs`. 
I logged in the web server container using `docker exec -it paperless-webserver-1 bash`.
```
root@c95f0258d544:/usr/src/paperless/src# tesseract --list-langs
List of available languages (7):
chi_sim
deu
eng
fra
ita
osd
spa
```
Here the `chi-sim`  appears as `chi_sim`

**3. Solution**:  for users using some language, like Chinese, Korean or Arabic, etc.
`PAPERLESS_OCR_LANGUAGES`: this env parameter tells which tesseract-ocr packages to install
`PAPERLESS_OCR_LANGUAGE`: this env parameter tells which language in `tesseract --list-langs` will be used for OCR.

In this Chinese Simplified language situation, after setting:
```
PAPERLESS_OCR_LANGUAGE=eng+chi_sim
PAPERLESS_OCR_LANGUAGES=eng chi-sim
```
the webserver container could start correctly.

**4. Potential Update**
It's better to  make `get_tesseract_langs()` function's output (in `paperless-ngx/src/paperless_tesseract/checks.py`) consistent with the `apt-get install tesseract-ocr-$lang`.


### Steps to reproduce

1. Use the lazy installer `bash -c "$(curl -L https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/install-paperless-ngx.sh)"` or set  `PAPERLESS_OCR_LANGUAGE=eng+chi-sim` and  `PAPERLESS_OCR_LANGUAGES=eng chi-sim`
2. The server cannot pass the language checks


### Webserver logs

```bash
paperless-webserver-1  | Paperless-ngx docker container starting...
paperless-webserver-1  | Installing languages...
paperless-webserver-1  | Hit:1 http://deb.debian.org/debian bullseye InRelease
paperless-webserver-1  | Hit:2 http://deb.debian.org/debian-security bullseye-security InRelease
paperless-webserver-1  | Hit:3 http://deb.debian.org/debian bullseye-updates InRelease
paperless-webserver-1  | Reading package lists...
paperless-webserver-1  | Package tesseract-ocr-eng already installed!
paperless-webserver-1  | Package tesseract-ocr-chi-sim already installed!
paperless-webserver-1  | Creating directory /tmp/paperless
paperless-webserver-1  | Adjusting permissions of paperless files. This may take a while.
paperless-webserver-1  | Waiting for PostgreSQL to start...
paperless-webserver-1  | Waiting for Redis...
paperless-webserver-1  | Connected to Redis broker.
paperless-webserver-1  | Apply database migrations...
paperless-webserver-1  | SystemCheckError: System check identified some issues:
paperless-webserver-1  | 
paperless-webserver-1  | ERRORS:
paperless-
```


### Browser logs

_No response_

### Paperless-ngx version

1.9.2

### Host OS

Ubuntu 22.04

### Installation method

Docker - official image

### Browser

_No response_

### Configuration changes

_No response_

### Other

_No response_


Discussion:

Resolving patch:
diff --git a/src/paperless_tesseract/checks.py b/src/paperless_tesseract/checks.py
--- a/src/paperless_tesseract/checks.py
+++ b/src/paperless_tesseract/checks.py
@@ -1,3 +1,4 @@
+import shutil
 import subprocess
 
 from django.conf import settings
@@ -7,10 +8,16 @@
 
 
 def get_tesseract_langs():
-    with subprocess.Popen(["tesseract", "--list-langs"], stdout=subprocess.PIPE) as p:
-        stdout, stderr = p.communicate()
+    proc = subprocess.run(
+        [shutil.which("tesseract"), "--list-langs"],
+        capture_output=True,
+    )
 
-    return stdout.decode().strip().split("\n")[1:]
+    # Decode bytes to string, split on newlines, trim out the header
+    proc_lines = proc.stdout.decode("utf8", errors="ignore").strip().split("\n")[1:]
+
+    # Replace _ with - to convert two part languages to the expected code
+    return [x.replace("_", "-") for x in proc_lines]
 
 
 @register()


Test patch: