From e80e5482f249b7d17c762d0cb8eb96935942678f Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Mon, 27 May 2024 19:37:58 +0530 Subject: [PATCH] add envvar to prefer autodetect over source lang --- README.md | 1 + pages/index.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c3b874..371f622 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Features of Mozhi can be customized and toggled on/off using Environment Variabl - `MOZHI_PORT`: Port the webserver listens on (if hosting API) - `MOZHI_LIBRETRANSLATE_URL`: URL of Libretranslate instance (Example: `MOZHI_LIBRETRANSLATE_URL=https://lt.psf.lt`) - `MOZHI_DEFAULT_SOURCE_LANG`: Language to default to if no source language is set by user. Defaults to Auto-Detect (or first available language in engines which dont support it) +- `MOZHI_DEFAULT_PREFER_AUTODETECT`: Prefer autodetect if available instead of specified/default source language. Defaults to false - `MOZHI_DEFAULT_TARGET_LANG`: Language to default to if no target language is set by user. Defaults to English These envvars turn off/on engines. By default all of them are enabled. diff --git a/pages/index.go b/pages/index.go index 928fd48..7bacf54 100644 --- a/pages/index.go +++ b/pages/index.go @@ -93,8 +93,9 @@ func HandleIndex(c *fiber.Ctx) error { } defaultLang := os.Getenv("MOZHI_DEFAULT_SOURCE_LANG") + preferAutoDetect := os.Getenv("MOZHI_DEFAULT_PREFER_AUTODETECT") defaultLangTarget := os.Getenv("MOZHI_DEFAULT_TARGET_LANG") - if defaultLang == "" { + if defaultLang == "" || preferAutoDetect == "true" { defaultLang = "auto" } if defaultLangTarget == "" {