feat(admin): add tessdata language management for OCR and download support (#5519)

# Description of Changes

### What was changed
- Added new admin-only API endpoints to:
  - List installed tessdata OCR languages
- Fetch available tessdata languages from the official Tesseract
repository
- Download selected tessdata language files directly into the configured
tessdata directory
- Implemented server-side validation, safe language name handling, and
directory writability checks.
- Extended the Admin Advanced Settings UI to:
  - Display installed tessdata languages
  - Show available remote languages not yet installed
- Allow selecting and downloading additional languages via a
multi-select UI
- Gracefully fall back to manual download links when the tessdata
directory is not writable
- Added new i18n strings for all related UI states (loading, success,
error, permission warnings).

### Why the change was made
- Managing OCR languages previously required manual filesystem
interaction.
- This change improves usability for administrators by enabling in-app
management of tessdata languages while maintaining security constraints.
- The writable directory check and manual fallback ensure compatibility
with restricted or containerized environments.


<img width="1282" height="832" alt="image"
src="https://github.com/user-attachments/assets/aa958730-0ffb-4fd6-9af8-87c527a476e4"
/>


---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Ludy
2026-01-21 22:10:47 +00:00
committed by GitHub
co-authored by Copilot
parent 23f872823d
commit 1436821a3a
4 changed files with 922 additions and 2 deletions
@@ -4836,6 +4836,26 @@ description = "Maximum DPI for image processing (0 = unlimited)"
[admin.settings.advanced.tessdataDir]
label = "Tessdata Directory"
description = "Path to the tessdata directory for OCR language files"
downloadMissingTitle = "No language selected"
downloadMissingBody = "Please select at least one language to download."
downloadSuccessTitle = "Languages downloaded"
downloadSuccessBody = "The selected tessdata languages have been saved."
downloadErrorTitle = "Download Failed"
loadingLanguages = "Loading installed tessdata languages..."
installedLanguages = "Installed tessdata languages"
noLanguages = "No tessdata languages found in the configured directory."
downloadLabel = "Download additional tessdata languages"
downloadPlaceholder = "Select languages"
downloadNothingFound = "No additional languages found"
permissionNotice = "The tessdata path is not writable. Downloads will be opened in the browser; please save the .traineddata files manually into the tessdata folder."
manualLinks = "Manual downloads: click the links and place the files into the tessdata folder."
downloadButton = "Download selected languages"
downloadInvalidTitle = "Invalid selection"
downloadInvalidBody = "Some selected languages are not available to download. Please refresh and choose from the list."
downloadErrorNetwork = "Download failed due to a network error. Please check your connection and try again."
downloadErrorServer = "The server encountered an error while downloading tessdata languages. Please try again later."
downloadErrorPermission = "Tessdata directory is not writable: {{message}}. Please choose a writable directory (e.g. under the application data folder) or adjust permissions."
downloadErrorGeneric = "Download failed: {{message}}. Please try again later."
[admin.settings.advanced.disableSanitize]
label = "Disable HTML Sanitization"