diff --git a/README.md b/README.md index daad3d7ece9061cc0b84d320abf7c85dd77ad151..2883ab4b32d87e404ca5e88ad6cb0a1b8fd583cf 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ Free and Open Source Machine Translation API, entirely self-hosted. Unlike other ## API Examples + +### Plain Text + Request: ```javascript @@ -36,6 +39,33 @@ Response: } ``` +### HTML + +Request: + +```javascript +const res = await fetch("https://libretranslate.com/translate", { + method: "POST", + body: JSON.stringify({ + q: '<a href="#" class="green">Hello!</a>', + source: "en", + target: "es", + format: "html" + }), + headers: { "Content-Type": "application/json" } +}); + +console.log(await res.json()); +``` + +Response: + +```javascript +{ + "translatedText": "<a href\"#='class=\"green\"'>¡Hola!</a>" +} +``` + ## Install and Run You can run your own API server in just a few lines of setup! @@ -136,7 +166,6 @@ You can pass application arguments directly to Gunicorn via: gunicorn --bind 0.0.0.0:5000 'wsgi:app(api_keys=True)' ``` - ## Manage API Keys LibreTranslate supports per-user limit quotas, e.g. you can issue API keys to users so that they can enjoy higher requests limits per minute (if you also set `--req-limit`). By default all users are rate-limited based on `--req-limit`, but passing an optional `api_key` parameter to the REST endpoints allows a user to enjoy higher request limits. diff --git a/app/app.py b/app/app.py index 19bb846cc6ce016a72cf8dc6890728f0fed00cb1..8576996434b444168a21fd42bb57cde9d2c9339d 100644 --- a/app/app.py +++ b/app/app.py @@ -267,9 +267,14 @@ def create_app(args): name: format schema: type: string - example: html or text + enum: [text, html] + default: text + example: text required: false - description: The format of the source text + description: > + Format of source text: + * `text` - Plain text + * `html` - HTML markup - in: formData name: api_key schema: