Skip to content

Commit 08c8524

Browse files
committed
pref: better language support
1 parent 2768274 commit 08c8524

16 files changed

+21
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ docker run -d -p 8080:8080 --restart=unless-stopped --name lessapi-duckduckgo le
4646
**Request Parameters:**
4747

4848
- keyword: Search keyword (required)
49-
- region: Region (optional) such as wt-wt, us-en, uk-en, ru-ru, etc. Default is wt-wt
49+
- region: Region (optional) such as en-US, fr-FR, zh-CN, ru-RU, etc. Default is en-US
5050
- maxCount: Maximum number of results returned (optional) Default is 20
5151
- viaProxyUrl: The address of the proxy used by the browser (optional) e.g., http://proxy.server:3000 Default is empty
5252

docs/de/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Einfach, leicht, zuverlässig, Docker-Deployment, einfach zu warten.
4141
**Anforderungsparameter:**
4242

4343
- keyword: Suchschlüsselwort (Pflichtfeld)
44-
- region: Region (optional) z.B. wt-wt, us-en, uk-en, ru-ru, usw. Standardwert ist wt-wt
44+
- region: Region (optional) z.B. en-US, fr-FR, zh-CN, ru-RU, usw. Standardwert ist en-US
4545
- maxCount: Maximale Rückgabeanzahl (optional) Standardwert ist 20
4646
- viaProxyUrl: Adresse des Proxys, der vom Browser verwendet wird (optional) z.B. http://proxy.server:3000 Standardwert
4747
ist leer

docs/es/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Es simple, ligero, confiable, se puede desplegar con Docker y fácil de mantener
4242
**Parámetros de solicitud:**
4343

4444
- keyword: Palabra clave de búsqueda (obligatorio)
45-
- region: Región (opcional) como wt-wt, us-en, uk-en, ru-ru, etc. El valor predeterminado es wt-wt
45+
- region: Región (opcional) como en-US, fr-FR, zh-CN, ru-RU, etc. El valor predeterminado es en-US
4646
- maxCount: Número máximo de resultados devueltos (opcional) El valor predeterminado es 20
4747
- viaProxyUrl: Dirección del proxy utilizado por el navegador (opcional) como http://proxy.server:3000 El valor
4848
predeterminado es vacío

docs/fr/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Simple, léger, fiable, déployable via Docker, facile à maintenir.
4141
**Paramètres de la requête:**
4242

4343
- keyword: Mot-clé de recherche (obligatoire)
44-
- region: Région (facultatif) wt-wt, us-en, uk-en, ru-ru, etc. La valeur par défaut est wt-wt
44+
- region: Région (facultatif) en-US, fr-FR, zh-CN, ru-RU, etc. La valeur par défaut est en-US
4545
- maxCount: Nombre maximal de résultats retournés (facultatif) La valeur par défaut est 20
4646
- viaProxyUrl: Adresse du proxy utilisé par le navigateur (facultatif) Exemple : http://proxy.server:3000 La valeur par
4747
défaut est vide

docs/it/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ offre un'interfaccia API semplice, leggera e affidabile, ed è facilmente manten
4040
**Parametri della richiesta:**
4141

4242
- keyword: parola chiave da cercare (obbligatorio)
43-
- region: regione (facoltativo) es. wt-wt, us-en, uk-en, ru-ru, ecc. Il valore predefinito è wt-wt
43+
- region: regione (facoltativo) es. en-US, fr-FR, zh-CN, ru-RU, ecc. Il valore predefinito è en-US
4444
- maxCount: numero massimo di risultati restituiti (facoltativo) Il valore predefinito è 20
4545
- viaProxyUrl: indirizzo del proxy da utilizzare con il browser (facoltativo) ad esempio http://proxy.server:3000 Il
4646
valore predefinito è vuoto

docs/ja/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ playwright と DuckDuckGo 検索エンジンを基に、単純なAPIインター
4040
**リクエストパラメータ:**
4141

4242
- keyword: 検索キーワード(必須)
43-
- region: 地域(任意) wt-wt, us-en, uk-en, ru-ru, など。デフォルト値は wt-wt
43+
- region: 地域(任意) en-US, fr-FR, zh-CN, ru-RU, など。デフォルト値は en-US
4444
- maxCount: 最大返信数(任意) デフォルト値は 20
4545
- viaProxyUrl: ブラウザが使用するプロキシのアドレス(任意) 例: http://proxy.server:3000 デフォルト値は空
4646

docs/ko/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ LessAPI-DuckDuckGo는 DuckDuckGo 검색 엔진을 기반으로 하는 간단한
3939
**요청 매개 변수:**
4040

4141
- keyword: 검색 키워드(필수)
42-
- region: 지역(선택) wt-wt, us-en, uk-en, ru-ru, 등 기본값 wt-wt
42+
- region: 지역(선택) en-US, fr-FR, zh-CN, ru-RU, 등 기본값 en-US
4343
- maxCount: 최대 반환 수(선택) 기본값 20
4444
- viaProxyUrl: 브라우저가 프록시를 사용하는 주소(선택) 예: http://proxy.server:3000 기본값: 빈 문자열
4545

docs/pt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Simples, leve, confiável, implantado com Docker, fácil de manter.
4141
**Parâmetros de solicitação:**
4242

4343
- keyword: Palavra-chave de pesquisa (obrigatório)
44-
- region: Região (opcional) como wt-wt, us-en, uk-en, ru-ru, etc. O valor padrão é wt-wt
44+
- region: Região (opcional) como en-US, fr-FR, zh-CN, ru-RU, etc. O valor padrão é en-US
4545
- maxCount: Número máximo de resultados retornados (opcional) O valor padrão é 20
4646
- viaProxyUrl: Endereço do proxy usado pelo navegador (opcional) como http://proxy.server:3000 O valor padrão é vazio
4747

docs/ru/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ LessAPI-DuckDuckGo является сервисом API поисковой си
4141
**Параметры запроса:**
4242

4343
- keyword: поисковые ключевые слова (обязательно)
44-
- region: регион (опционально) wt-wt, us-en, uk-en, ru-ru и т.д. Значение по умолчанию wt-wt
44+
- region: регион (опционально) en-US, fr-FR, zh-CN, ru-RU и т.д. Значение по умолчанию en-US
4545
- maxCount: максимальное количество возвращаемых результатов (опционально) Значение по умолчанию 20
4646
- viaProxyUrl: адрес прокси для браузера (опционально) Например, http://proxy.server:3000 Значение по умолчанию пустое
4747

docs/zhs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ docker run -d -p 8080:8080 --restart=unless-stopped --name lessapi-duckduckgo le
4949
**请求参数:**
5050

5151
- keyword: 搜索关键字(必填)
52-
- region: 地区(选填) wt-wt, us-en, uk-en, ru-ru, 等 默认值 wt-wt
52+
- region: 地区(选填) en-US, fr-FR, zh-CN, ru-RU, 等 默认值 en-US
5353
- maxCount: 最大返回数量(选填) 默认值 20
5454
- viaProxyUrl: 浏览器使用代理的地址(选填) 如 http://proxy.server:3000 默认值 空
5555

docs/zht/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ LessAPI-DuckDuckGo 是一個搜索引擎API服務。
4242
**請求參數:**
4343

4444
- keyword: 搜索關鍵字(必填)
45-
- region: 地區(選填) wt-wt, us-en, uk-en, ru-ru, 等 預設值 wt-wt
45+
- region: 地區(選填) en-US, fr-FR, zh-CN, ru-RU, 等 預設值 en-US
4646
- maxCount: 最大返回數量(選填) 預設值 20
4747
- viaProxyUrl: 瀏覽器使用代理的地址(選填) 如 http://proxy.server:3000 預設值 空
4848

internal/searchs/browser_support.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/lessapidev/lessapi-duckduckgo/internal/utils"
66
"github.com/playwright-community/playwright-go"
7+
"strings"
78
)
89

910
// NewBrowserContextWithOptions creates a new browser context with options
@@ -27,9 +28,11 @@ func NewBrowserContextWithOptions(opt BrowserOptions) (playwright.BrowserContext
2728
}
2829

2930
// create new context
30-
pLocate := opt.Locate
31+
pLocate := opt.Language
3132
if pLocate == nil {
32-
pLocate = playwright.String("en-Us")
33+
pLocate = playwright.String("en-US")
34+
} else {
35+
pLocate = playwright.String(strings.ReplaceAll(*pLocate, "_", "-"))
3336
}
3437
pViewport := &playwright.Size{
3538
Width: 1920,

internal/searchs/browser_support_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package searchs
44
type BrowserOptions struct {
55
ProxyServer *string
66
EnableStealthJs *bool
7-
Locate *string
7+
Language *string
88
viewportWidth *int
99
viewportHeight *int
1010
}

internal/searchs/search_text.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func SearchText(param types.SearchTextPayload) (*types.SearchTextResponse, error
1515
return nil, fmt.Errorf("keyword is required")
1616
}
1717
if param.Region == "" {
18-
param.Region = "wt-wt"
18+
param.Region = "en-US"
1919
}
2020
if param.TimeLimit == "" {
2121
param.TimeLimit = ""
@@ -35,7 +35,7 @@ func SearchText(param types.SearchTextPayload) (*types.SearchTextResponse, error
3535
browserOpt := BrowserOptions{
3636
ProxyServer: &param.ViaProxyUrl,
3737
EnableStealthJs: playwright.Bool(true),
38-
Locate: &param.Region,
38+
Language: &param.Region,
3939
viewportWidth: playwright.Int(1920),
4040
viewportHeight: playwright.Int(1080 - 35),
4141
}

internal/types/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type ApiResponse[T any] struct {
99
type SearchTextPayload struct {
1010
// Keywords to search (required)
1111
Keyword string `json:"keyword" form:"keyword" validate:"required"`
12-
// Region to search (optional) (default "wt-wt")
12+
// Region to search (optional) (default "en-US")
1313
Region string `json:"region" form:"region"`
1414
// Time limit to search (optional) ( "" default all , "d" past day, "w" past week, "m" past month, "y" past year)
1515
TimeLimit string `json:"timeLimit" form:"timeLimit"`

resource/openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{
2828
"name": "region",
2929
"in": "query",
30-
"description": "locate region. wt-wt, us-en, uk-en, ru-ru, etc. Defaults to \"wt-wt\".",
30+
"description": "locate region. en-US, fr-FR, zh-CN, ru-RU, etc. Defaults to \"en-US\".",
3131
"required": false,
3232
"schema": {
3333
"type": "string"

0 commit comments

Comments
 (0)