prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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_
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/paperless_tesseract/checks.py`
  Content:
  ```
  1 import subprocess
  2 
  3 from django.conf import settings
  4 from django.core.checks import Error
  5 from django.core.checks import register
  6 from django.core.checks import Warning
  7 
  8 
  9 def get_tesseract_langs():
  10     with subprocess.Popen(["tesseract", "--list-langs"], stdout=subprocess.PIPE) as p:
  11         stdout, stderr = p.communicate()
  12 
  13     return stdout.decode().strip().split("\n")[1:]
  14 
  15 
  16 @register()
  17 def check_default_language_available(app_configs, **kwargs):
  18     installed_langs = get_tesseract_langs()
  19 
  20     if not settings.OCR_LANGUAGE:
  21         return [
  22             Warning(
  23                 "No OCR language has been specified with PAPERLESS_OCR_LANGUAGE. "
  24                 "This means that tesseract will fallback to english.",
  25             ),
  26         ]
  27 
  28     specified_langs = settings.OCR_LANGUAGE.split("+")
  29 
  30     for lang in specified_langs:
  31         if lang not in installed_langs:
  32             return [
  33                 Error(
  34                     f"The selected ocr language {lang} is "
  35                     f"not installed. Paperless cannot OCR your documents "
  36                     f"without it. Please fix PAPERLESS_OCR_LANGUAGE.",
  37                 ),
  38             ]
  39 
  40     return []
  41
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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()
  
verification_info: {"golden_diff": "diff --git a/src/paperless_tesseract/checks.py b/src/paperless_tesseract/checks.py\n--- a/src/paperless_tesseract/checks.py\n+++ b/src/paperless_tesseract/checks.py\n@@ -1,3 +1,4 @@\n+import shutil\n import subprocess\n \n from django.conf import settings\n@@ -7,10 +8,16 @@\n \n \n def get_tesseract_langs():\n-    with subprocess.Popen([\"tesseract\", \"--list-langs\"], stdout=subprocess.PIPE) as p:\n-        stdout, stderr = p.communicate()\n+    proc = subprocess.run(\n+        [shutil.which(\"tesseract\"), \"--list-langs\"],\n+        capture_output=True,\n+    )\n \n-    return stdout.decode().strip().split(\"\\n\")[1:]\n+    # Decode bytes to string, split on newlines, trim out the header\n+    proc_lines = proc.stdout.decode(\"utf8\", errors=\"ignore\").strip().split(\"\\n\")[1:]\n+\n+    # Replace _ with - to convert two part languages to the expected code\n+    return [x.replace(\"_\", \"-\") for x in proc_lines]\n \n \n @register()\n", "issue": "[BUG] Tesseract checks function doesn't recognize Chinese language (and some other languages) correctly\n### Description\r\n\r\nGood morning, I am new user of paperless-ngx. I tried to start a container using the lazy installation scripts.\r\n`bash -c \"$(curl -L https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/install-paperless-ngx.sh)\"`\r\n\r\n**1. Problem Description**: when I set `PAPERLESS_OCR_LANGUAGE=eng+chi-sim`, the webserver cannot start correctly because it fails the tesseract language checks.\r\n\r\n**2. Reason of the problem**: \r\nIn `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`.\r\n\r\nHowever, when `-ngx` checks if the tesseract language package exists, it calls `tesseract --list-langs`. \r\nI logged in the web server container using `docker exec -it paperless-webserver-1 bash`.\r\n```\r\nroot@c95f0258d544:/usr/src/paperless/src# tesseract --list-langs\r\nList of available languages (7):\r\nchi_sim\r\ndeu\r\neng\r\nfra\r\nita\r\nosd\r\nspa\r\n```\r\nHere the `chi-sim`  appears as `chi_sim`\r\n\r\n**3. Solution**:  for users using some language, like Chinese, Korean or Arabic, etc.\r\n`PAPERLESS_OCR_LANGUAGES`: this env parameter tells which tesseract-ocr packages to install\r\n`PAPERLESS_OCR_LANGUAGE`: this env parameter tells which language in `tesseract --list-langs` will be used for OCR.\r\n\r\nIn this Chinese Simplified language situation, after setting:\r\n```\r\nPAPERLESS_OCR_LANGUAGE=eng+chi_sim\r\nPAPERLESS_OCR_LANGUAGES=eng chi-sim\r\n```\r\nthe webserver container could start correctly.\r\n\r\n**4. Potential Update**\r\nIt'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`.\r\n\r\n\r\n### Steps to reproduce\r\n\r\n1. 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`\r\n2. The server cannot pass the language checks\r\n\r\n\r\n### Webserver logs\r\n\r\n```bash\r\npaperless-webserver-1  | Paperless-ngx docker container starting...\r\npaperless-webserver-1  | Installing languages...\r\npaperless-webserver-1  | Hit:1 http://deb.debian.org/debian bullseye InRelease\r\npaperless-webserver-1  | Hit:2 http://deb.debian.org/debian-security bullseye-security InRelease\r\npaperless-webserver-1  | Hit:3 http://deb.debian.org/debian bullseye-updates InRelease\r\npaperless-webserver-1  | Reading package lists...\r\npaperless-webserver-1  | Package tesseract-ocr-eng already installed!\r\npaperless-webserver-1  | Package tesseract-ocr-chi-sim already installed!\r\npaperless-webserver-1  | Creating directory /tmp/paperless\r\npaperless-webserver-1  | Adjusting permissions of paperless files. This may take a while.\r\npaperless-webserver-1  | Waiting for PostgreSQL to start...\r\npaperless-webserver-1  | Waiting for Redis...\r\npaperless-webserver-1  | Connected to Redis broker.\r\npaperless-webserver-1  | Apply database migrations...\r\npaperless-webserver-1  | SystemCheckError: System check identified some issues:\r\npaperless-webserver-1  | \r\npaperless-webserver-1  | ERRORS:\r\npaperless-\r\n```\r\n\r\n\r\n### Browser logs\r\n\r\n_No response_\r\n\r\n### Paperless-ngx version\r\n\r\n1.9.2\r\n\r\n### Host OS\r\n\r\nUbuntu 22.04\r\n\r\n### Installation method\r\n\r\nDocker - official image\r\n\r\n### Browser\r\n\r\n_No response_\r\n\r\n### Configuration changes\r\n\r\n_No response_\r\n\r\n### Other\r\n\r\n_No response_\n", "before_files": [{"content": "import subprocess\n\nfrom django.conf import settings\nfrom django.core.checks import Error\nfrom django.core.checks import register\nfrom django.core.checks import Warning\n\n\ndef get_tesseract_langs():\n    with subprocess.Popen([\"tesseract\", \"--list-langs\"], stdout=subprocess.PIPE) as p:\n        stdout, stderr = p.communicate()\n\n    return stdout.decode().strip().split(\"\\n\")[1:]\n\n\n@register()\ndef check_default_language_available(app_configs, **kwargs):\n    installed_langs = get_tesseract_langs()\n\n    if not settings.OCR_LANGUAGE:\n        return [\n            Warning(\n                \"No OCR language has been specified with PAPERLESS_OCR_LANGUAGE. \"\n                \"This means that tesseract will fallback to english.\",\n            ),\n        ]\n\n    specified_langs = settings.OCR_LANGUAGE.split(\"+\")\n\n    for lang in specified_langs:\n        if lang not in installed_langs:\n            return [\n                Error(\n                    f\"The selected ocr language {lang} is \"\n                    f\"not installed. Paperless cannot OCR your documents \"\n                    f\"without it. Please fix PAPERLESS_OCR_LANGUAGE.\",\n                ),\n            ]\n\n    return []\n", "path": "src/paperless_tesseract/checks.py"}], "after_files": [{"content": "import shutil\nimport subprocess\n\nfrom django.conf import settings\nfrom django.core.checks import Error\nfrom django.core.checks import register\nfrom django.core.checks import Warning\n\n\ndef get_tesseract_langs():\n    proc = subprocess.run(\n        [shutil.which(\"tesseract\"), \"--list-langs\"],\n        capture_output=True,\n    )\n\n    # Decode bytes to string, split on newlines, trim out the header\n    proc_lines = proc.stdout.decode(\"utf8\", errors=\"ignore\").strip().split(\"\\n\")[1:]\n\n    # Replace _ with - to convert two part languages to the expected code\n    return [x.replace(\"_\", \"-\") for x in proc_lines]\n\n\n@register()\ndef check_default_language_available(app_configs, **kwargs):\n    installed_langs = get_tesseract_langs()\n\n    if not settings.OCR_LANGUAGE:\n        return [\n            Warning(\n                \"No OCR language has been specified with PAPERLESS_OCR_LANGUAGE. \"\n                \"This means that tesseract will fallback to english.\",\n            ),\n        ]\n\n    specified_langs = settings.OCR_LANGUAGE.split(\"+\")\n\n    for lang in specified_langs:\n        if lang not in installed_langs:\n            return [\n                Error(\n                    f\"The selected ocr language {lang} is \"\n                    f\"not installed. Paperless cannot OCR your documents \"\n                    f\"without it. Please fix PAPERLESS_OCR_LANGUAGE.\",\n                ),\n            ]\n\n    return []\n", "path": "src/paperless_tesseract/checks.py"}]}