### Start Development Server Source: https://github.com/xxnuo/mtranserver/blob/main/docs/README.md Starts the Rspress development server, allowing for live preview and hot-reloading during development. ```bash npm run dev ``` -------------------------------- ### Preview Production Build Source: https://github.com/xxnuo/mtranserver/blob/main/docs/README.md Starts a local server to preview the production build of the Rspress website. ```bash npm run preview ``` -------------------------------- ### Install npm Dependencies Source: https://github.com/xxnuo/mtranserver/blob/main/docs/README.md Installs all necessary project dependencies using npm. This is the first step before running any other commands. ```bash npm install ``` -------------------------------- ### Docker Compose Deployment and Management Source: https://github.com/xxnuo/mtranserver/blob/main/README_en.md Commands for setting up, running, and updating the mtranserver service using Docker Compose. Includes initial setup, starting the service, running in detached mode, and pulling the latest image. ```bash mkdir mtranserver cd mtranserver touch compose.yml ``` ```bash docker compose up ``` ```bash docker compose up -d ``` ```bash cd mtranserver docker pull xxnuo/mtranserver:latest docker compose up -d ``` -------------------------------- ### Build for Production Source: https://github.com/xxnuo/mtranserver/blob/main/docs/README.md Generates a production-ready build of the Rspress website, optimized for deployment. ```bash npm run build ``` -------------------------------- ### Start mtranserver Service (Foreground) Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Starts the mtranserver service using Docker Compose in the foreground. This command is useful for monitoring logs during initial startup and debugging. It will display service output directly in the terminal. ```bash docker compose up ``` -------------------------------- ### Docker Deployment Source: https://github.com/xxnuo/mtranserver/blob/main/README_en.md Instructions for deploying the MTranServer using Docker. This command starts the server in detached mode, maps the port, names the container, and sets an API token. ```bash docker run -d --name mtranserver -p 8989:8989 -e API_TOKEN=your_token xxnuo/mtranserver:latest ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Example Docker Compose file for deploying MTranServer. It specifies the image, container name, restart policy, port mapping, volume for models, and an environment variable for an API token. ```yaml services: mtranserver: image: xxnuo/mtranserver:latest container_name: mtranserver restart: unless-stopped ports: - "8989:8989" volumes: - ./models:/app/models environment: - CORE_API_TOKEN=your_token ``` -------------------------------- ### Start mtranserver Service (Detached) Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Starts the mtranserver service using Docker Compose in detached mode. This command runs the service in the background, allowing you to continue using the terminal. Use `docker compose down` to stop it. ```bash docker compose up -d ``` -------------------------------- ### MTranServer API Documentation Source: https://github.com/xxnuo/mtranserver/blob/main/README_en.md Details on accessing the MTranServer API, including available endpoints, parameters, and expected responses. The server exposes its functionality via a RESTful API, accessible through Swagger UI. ```APIDOC MTranServer API Overview: This API provides offline translation services. The server is accessible via HTTP, typically on port 8989. Base URL: http://localhost:8989 Authentication: - API_TOKEN environment variable is used for authentication. Endpoints: 1. Translate Text: - Method: POST - Path: /translate - Description: Translates input text from a source language to a target language. - Request Body: { "text": "string", // The text to translate "source_lang": "string", // Source language code (e.g., 'en') "target_lang": "string" // Target language code (e.g., 'zh') } - Response Body: { "translated_text": "string", // The translated text "source_lang": "string", "target_lang": "string" } - Example: POST /translate { "text": "Hello world", "source_lang": "en", "target_lang": "zh" } -> { "translated_text": "你好世界", "source_lang": "en", "target_lang": "zh" } 2. Get Supported Languages: - Method: GET - Path: /languages - Description: Returns a list of supported language pairs. - Response Body: { "languages": [ {"code": "en", "name": "English"}, {"code": "zh", "name": "Chinese"}, {"code": "ja", "name": "Japanese"} // ... other supported languages ] } Notes: - The specific language codes and available pairs depend on the loaded models. - The server automatically downloads models if built-in models are not available. - Refer to Swagger UI for the most up-to-date API specification and interactive documentation. ``` -------------------------------- ### MTranServer Developer API Reference Source: https://github.com/xxnuo/mtranserver/blob/main/README.md Comprehensive documentation for the MTranServer developer API, covering base URL, available endpoints, request/response formats, and authentication headers. This includes versioning, language support, translation endpoints, and health checks. ```APIDOC Base URL: http://localhost:8989 API Documentation available at: http://localhost:8989/docs (v3.0.0+) Endpoints: - Service Version: URL: /version Request Format: None Response Format: {"version": "v3.0.0"} Authentication: None - Supported Languages List: URL: /languages Request Format: None Response Format: {"languages":["en","zh","ja","ko"...]} Authentication: Authorization: your_token - Standard Translation: URL: /translate Request Format: {"from": "en", "to": "zh", "text": "Hello, world!"} Response Format: {"result": "你好,世界!"} Authentication: Authorization: your_token - Batch Translation: URL: /translate/batch Request Format: {"from": "en", "to": "zh", "texts": ["Hello, world!", "Hello, world!"]} Response Format: {"results": ["你好,世界!", "你好,世界!"]} Authentication: Authorization: your_token - Health Check: URL: /health Request Format: None Response Format: {"status": "ok"} Authentication: None - Heartbeat Check: URL: /__heartbeat__ Request Format: None Response Format: Ready Authentication: None - Load Balancer Heartbeat Check: URL: /__lbheartbeat__ Request Format: None Response Format: Ready Authentication: None - Google Translate Compatible API v2: URL: /language/translate/v2 Request Format: {"q": "The Great Pyramid of Giza", "source": "en", "target": "zh", "format": "text"} Response Format: {"data": {"translations": [{"translatedText": "吉萨大金字塔"}]}} Authentication: Authorization: your_token Note: For advanced developer settings, refer to CONFIG.md. ``` -------------------------------- ### Update MTranServer Source: https://github.com/xxnuo/mtranserver/blob/main/README.md Instructions to update the MTranServer Docker image and restart the service. This involves navigating to the project directory, pulling the latest image, and bringing up the containers. ```bash cd mtranserver docker pull xxnuo/mtranserver:latest docker compose up -d ``` -------------------------------- ### Translation Plugin API Endpoints Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Configuration details for integrating various translation plugins with the mtranserver. This includes API URLs for Immersive Translate, Kiss Translator, and Huaci Translate, supporting both password-protected and unprotected access. Ensure `your_token` is replaced with your actual `CORE_API_TOKEN`. ```APIDOC Immersive Translate (No Password): URL: http://localhost:8989/imme Plugin Setting: '自定义API 设置' -> 'API URL' Immersive Translate (With Password): URL: http://localhost:8989/imme?token=your_token Plugin Setting: '自定义API 设置' -> 'API URL' Note: Replace 'your_token' with your CORE_API_TOKEN. Kiss Translator (No Password): URL: http://localhost:8989/kiss Plugin Setting: '接口设置' -> 'Custom' -> 'URL' Kiss Translator (With Password): URL: http://localhost:8989/kiss Plugin Setting: '接口设置' -> 'Custom' -> 'URL' Note: Set 'KEY' to your CORE_API_TOKEN. Huaci Translate (No Password): URL: http://localhost:8989/hcfy Plugin Setting: '设置' -> '其他' -> '自定义翻译源' -> '接口地址' Huaci Translate (With Password): URL: http://localhost:8989/hcfy?token=your_token Plugin Setting: '设置' -> '其他' -> '自定义翻译源' -> '接口地址' Note: Replace 'your_token' with your CORE_API_TOKEN. General Notes: - Replace 'localhost' with your server address or Docker container name. - The port '8989' can be changed based on your compose.yml configuration. - The first request might be slower due to model loading; subsequent requests will be faster. ``` -------------------------------- ### Docker Image Import Command Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Command to load a Docker image from a local .tar file, typically used when direct image pulling from a registry is not possible. ```bash docker load -i mtranserver.image.tar ``` -------------------------------- ### MTranServer Directory Structure Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Illustrates the expected file and directory structure for MTranServer, including the compose file and the models directory containing language model files. ```text mtranserver/ ├── compose.yml ├── models/ │ ├── enzh │ │ ├── lex.50.50.enzh.s2t.bin │ │ ├── model.enzh.intgemm.alphas.bin │ │ └── vocab.enzh.spm ``` -------------------------------- ### Multi-Language Model Directory Structure Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md Shows the directory structure when multiple language models, such as Chinese-to-English and English-to-Chinese, are downloaded and placed in the models directory. ```text compose.yml models/ ├── enzh │ ├── lex.50.50.enzh.s2t.bin │ ├── model.enzh.intgemm.alphas.bin │ └── vocab.enzh.spm ├── zhen │ ├── lex.50.50.zhen.t2s.bin │ ├── model.zhen.intgemm.alphas.bin │ └── vocab.zhen.spm ``` -------------------------------- ### mtranserver Docker Compose Configuration Source: https://github.com/xxnuo/mtranserver/blob/main/README_en.md The YAML configuration file for the mtranserver service in Docker Compose. It specifies the image, container name, restart policy, port mapping, and environment variables like the API token. ```yaml services: mtranserver: image: xxnuo/mtranserver:latest container_name: mtranserver restart: unless-stopped ports: - "8989:8989" environment: - CORE_API_TOKEN=your_token ``` -------------------------------- ### MTranServer API Endpoints Source: https://github.com/xxnuo/mtranserver/blob/main/README_en.md Provides details for various API endpoints offered by MTranServer, including their URLs, request/response formats, and authentication headers. This documentation covers translation services, language support, and health checks. ```APIDOC Base URL: http://localhost:8989 API Documentation Link: http://localhost:8989/docs (Swagger UI) Endpoints: - Service Version: URL: /version Request Format: None Response Format: {"version": "v3.0.0"} Auth Header: None - Supported Languages: URL: /languages Request Format: None Response Format: {"languages":["en","zh","ja","ko"...]} Auth Header: Authorization: your_token - Standard Translation: URL: /translate Request Format: {"from": "en", "to": "zh", "text": "Hello, world!"} Response Format: {"result": "你好,世界!"} Auth Header: Authorization: your_token - Batch Translation: URL: /translate/batch Request Format: {"from": "en", "to": "zh", "texts": ["Hello, world!", "Hello, world!"]} Response Format: {"results": ["你好,世界!", "你好,世界!"]} Auth Header: Authorization: your_token - Health Check: URL: /health Request Format: None Response Format: {"status": "ok"} Auth Header: None - Heartbeat Check: URL: /__heartbeat__ Request Format: None Response Format: Ready Auth Header: None - Load Balancer Heartbeat: URL: /__lbheartbeat__ Request Format: None Response Format: Ready Auth Header: None - Google Translate Compatible Interface 1: URL: /language/translate/v2 Request Format: {"q": "The Great Pyramid of Giza", "source": "en", "target": "zh", "format": "text"} Response Format: {"data": {"translations": [{"translatedText": "吉萨大金字塔"}]}} Auth Header: Authorization: your_token Note: Developer advanced settings refer to CONFIG.md. ``` -------------------------------- ### MTranServer API Endpoints Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md This section details the available API endpoints for the MTranServer, including their URLs, request/response formats, and authentication requirements. It covers core translation functionalities, model management, and server status checks. ```APIDOC Base URL: `http://localhost:8989` API Endpoints: - **Service Version** - URL: `/version` - Request Format: None - Response Format: `{"version": "v1.1.0"}` - Authentication: None - Description: Retrieves the current version of the MTranServer. - **Language Pair List** - URL: `/models` - Request Format: None - Response Format: `{"models":["zhen","enzh"]}` - Authentication: `Authorization: your_token` - Description: Lists available language pairs supported by the server. - **Standard Translation** - URL: `/translate` - Request Format: `{"from": "en", "to": "zh", "text": "Hello, world!"}` - Response Format: `{"result": "你好,世界!"}` - Authentication: `Authorization: your_token` - Description: Translates a single piece of text from a source language to a target language. - **Batch Translation** - URL: `/translate/batch` - Request Format: `{"from": "en", "to": "zh", "texts": ["Hello, world!", "Hello, world!"]}` - Response Format: `{"results": ["你好,世界!", "你好,世界!"]}` - Authentication: `Authorization: your_token` - Description: Translates multiple pieces of text in a single request. - **Health Check** - URL: `/health` - Request Format: None - Response Format: `{"status": "ok"}` - Authentication: None - Description: Checks the health status of the MTranServer. - **Heartbeat Check** - URL: `/__heartbeat__` - Request Format: None - Response Format: `Ready` - Authentication: None - Description: A simple heartbeat endpoint. - **Load Balancer Heartbeat Check** - URL: `/__lbheartbeat__` - Request Format: None - Response Format: `Ready` - Authentication: None - Description: Heartbeat endpoint specifically for load balancers. - **Google Translate Compatible Interface 1** - URL: `/language/translate/v2` - Request Format: `{"q": "The Great Pyramid of Giza", "source": "en", "target": "zh", "format": "text"}` - Response Format: `{"data": {"translations": [{"translatedText": "吉萨大金字塔"}]}}` - Authentication: `Authorization: your_token` - Description: An endpoint compatible with Google Translate's v2 API for translation. ``` -------------------------------- ### mtranserver Configuration File (config.ini) Source: https://github.com/xxnuo/mtranserver/blob/main/CONFIG.md This snippet shows the structure and default values for the mtranserver configuration file. It allows customization of API token, port, log level, worker threads, request timeout, and parallel translations. Settings in config.ini override environment variables. ```INI ; API token, default empty CORE_API_TOKEN=your_token ; Internal port, default 8989 CORE_PORT=8989 ; Log level, default WARNING CORE_LOG_LEVEL=WARNING ; Number of worker threads, default automatically set CORE_NUM_WORKERS= ; Request timeout, default 30000ms CORE_REQUEST_TIMEOUT= ; Maximum number of parallel translations, default automatically set CORE_MAX_PARALLEL_TRANSLATIONS= ``` -------------------------------- ### Update and Restart mtranserver Service Source: https://github.com/xxnuo/mtranserver/blob/main/docs/docs/zh/guide/index.md This sequence of commands stops the currently running mtranserver service, pulls the latest Docker image, and then restarts the service in detached mode. This is recommended for applying updates. ```bash docker compose down docker pull xxnuo/mtranserver:latest docker compose up -d ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.