diff --git a/.dockerignore b/.dockerignore index b94de4f..6b4c5ef 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,9 @@ .git* -docker +docker* .Dockerfile.swp + +chart/ +.editorconfig +*.yaml +*.md +!README.md diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..e8bdd99 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,7 @@ +--- +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily diff --git a/.github/workflows/issue-triage.yml b/.github/workflows/issue-triage.yml new file mode 100644 index 0000000..6af6281 --- /dev/null +++ b/.github/workflows/issue-triage.yml @@ -0,0 +1,32 @@ +name: Issue Triage +on: + issues: + types: + - opened +jobs: + issue_triage: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: pierotofy/issuewhiz@v1 + with: + ghToken: ${{ secrets.GITHUB_TOKEN }} + openAI: ${{ secrets.OPENAI_TOKEN }} + model: gpt-4o-2024-08-06 + filter: | + - "#" + variables: | + - Q: "A question about using a software or seeking guidance on doing something?" + - B: "Reporting an issue, an exception, a stack trace, or a software bug?" + - T: "Reporting a problem with an inaccurate, awkward or erroneous translation?" + - E: "Reporting about some missing feature or functionality?" + - SC: "Describes an issue related to compiling or building source code?" + logic: | + - "Q and (not B) and (not E) and (not SC)": [comment: "Could we move this conversation over to the forum at https://community.libretranslate.com? :pray: The forum is the right place to ask questions (we try to keep the GitHub issue tracker for feature requests and bugs only). Thank you! :+1:", close: true, stop: true] + - "B and (not T) and (not E) and (not SC)": [label: "possible bug", stop: true] + - "T and (not E)": [label: "model improvement", stop: true] + - "E": [label: "enhancement", stop: true] + - "SC": [label: "possible bug"] + + signature: "p.s. I'm just an automated script, not a human being." diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index a2b5ebb..8ca45a8 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -12,16 +12,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -33,7 +33,7 @@ jobs: echo ::set-output name=gh-username-lower::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') - name: Build and push Image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: file: ./docker/Dockerfile platforms: linux/amd64,linux/arm64 @@ -44,8 +44,24 @@ jobs: env: TAG: ${{ startsWith(github.ref, 'refs/tags/') && steps.get-variables.outputs.version || 'latest' }} + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: false + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true + - name: Build and push Cuda Image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: file: ./docker/cuda.Dockerfile platforms: linux/amd64 diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index a68ae51..fc14341 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -18,9 +18,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.8' - name: Install dependencies diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2703870..e39c792 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,9 +22,9 @@ jobs: python-version: ['3.8', '3.9', '3.10'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -41,7 +41,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Docker build run: docker build -f docker/Dockerfile -t libretranslate . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55e8f4b..82e8946 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,15 +9,6 @@ repos: name: " ✔️ Check TOML" - id: check-json name: " ✔️ Check JSON" - - id: trailing-whitespace - name: " ✂️ Trim trailing whitespaces" - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.277 - hooks: - - id: ruff - name: " ⚡️ Formatting code with Ruff" - args: - - --fix ci: autofix_commit_msg: 🎨 [pre-commit] Auto format diff --git a/.well-known/funding-manifest-urls b/.well-known/funding-manifest-urls new file mode 100644 index 0000000..b419350 --- /dev/null +++ b/.well-known/funding-manifest-urls @@ -0,0 +1,2 @@ +https://libretranslate.com/funding.json + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4bd0221..ee4ded6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -134,3 +134,7 @@ This prevents pip packages from being installed system-wide. This way, there are References: * [Python venv documentation](https://docs.python.org/library/venv.html) + +## Other Languages + +- [Español (CONTRIBUTING)](docs/CONTRIBUTING.es.md) \ No newline at end of file diff --git a/README.md b/README.md index 2e7a5fd..9eaa2ee 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ # LibreTranslate -[Try it online!](https://libretranslate.com) | [API Docs](https://libretranslate.com/docs) | [Community Forum](https://community.libretranslate.com/) +[Try it online!](https://libretranslate.com) | [API Docs](https://libretranslate.com/docs) | [Community Forum](https://community.libretranslate.com/) | [Bluesky](https://bsky.app/profile/libretranslate.com) [](https://pypi.org/project/libretranslate) [](https://github.com/LibreTranslate/LibreTranslate/actions?query=workflow%3A%22Run+tests%22) [](https://github.com/LibreTranslate/LibreTranslate/actions/workflows/publish-docker.yml) [](https://github.com/LibreTranslate/LibreTranslate/actions/workflows/publish-package.yml) [](https://codeberg.org/teaserbot-labs/delightful-humane-design) Free and Open Source Machine Translation API, entirely self-hosted. Unlike other APIs, it doesn't rely on proprietary providers such as Google or Azure to perform translations. Instead, its translation engine is powered by the open source [Argos Translate](https://github.com/argosopentech/argos-translate) library. - - -[Try it online!](https://libretranslate.com) | [API Docs](https://libretranslate.com/docs) + ## API Examples @@ -22,9 +20,9 @@ const res = await fetch("https://libretranslate.com/translate", { body: JSON.stringify({ q: "Hello!", source: "en", - target: "es" + target: "es", }), - headers: { "Content-Type": "application/json" } + headers: { "Content-Type": "application/json" }, }); console.log(await res.json()); @@ -38,6 +36,8 @@ Response: } ``` +List of language codes: https://libretranslate.com/languages + ### Auto Detect Language Request: @@ -48,9 +48,9 @@ const res = await fetch("https://libretranslate.com/translate", { body: JSON.stringify({ q: "Ciao!", source: "auto", - target: "en" + target: "en", }), - headers: { "Content-Type": "application/json" } + headers: { "Content-Type": "application/json" }, }); console.log(await res.json()); @@ -68,7 +68,7 @@ Response: } ``` -### HTML (beta) +### HTML Request: @@ -79,9 +79,9 @@ const res = await fetch("https://libretranslate.com/translate", { q: '
Hello!
', source: "en", target: "es", - format: "html" + format: "html", }), - headers: { "Content-Type": "application/json" } + headers: { "Content-Type": "application/json" }, }); console.log(await res.json()); @@ -95,6 +95,38 @@ Response: } ``` +### Alternative Translations + +Request: + +```javascript +const res = await fetch("https://libretranslate.com/translate", { + method: "POST", + body: JSON.stringify({ + q: "Hello", + source: "en", + target: "it", + format: "text", + alternatives: 3, + }), + headers: { "Content-Type": "application/json" }, +}); + +console.log(await res.json()); +``` + +Response: + +```javascript +{ + "alternatives": [ + "Salve", + "Pronto" + ], + "translatedText": "Ciao" +} +``` + ## Install and Run You can run your own API server with just a few lines of setup! @@ -108,6 +140,14 @@ libretranslate [args] Then open a web browser toHello!
', + source: "en", + target: "es", + format: "html", + }), + headers: { "Content-Type": "application/json" }, +}); + +console.log(await res.json()); +``` + +Respuesta: + +```javascript +{ + "translatedText": "¡Hola!
" +} +``` + +### Traducciones Alternativas + +Solicitud: + +```javascript +const res = await fetch("https://libretranslate.com/translate", { + method: "POST", + body: JSON.stringify({ + q: "Hello", + source: "en", + target: "it", + format: "text", + alternatives: 3, + }), + headers: { "Content-Type": "application/json" }, +}); + +console.log(await res.json()); +``` + +Respuesta: + +```javascript +{ + "alternatives": [ + "Salve", + "Pronto" + ], + "translatedText": "Ciao" +} +``` + +## Instalar y Ejecutar + +Puedes ejecutar tu propio servidor API con solo unas pocas líneas de configuración! + +Asegúrate de tener instalado Python (se recomienda la versión 3.8 o superior) y, a continuación, simplemente ejecuta: + +```bash +pip install libretranslate +libretranslate [args] +``` + +Luego abra un navegador web para