Reference

1
Last updated last month

Our API is following REST guidelines and is HTTP based.

Public Endpoints

get
Status

https://api.weglot.com
/public/status
This endpoint is used as a health check. You can use it to check if the Weglot API is up and running.
Request
Response
200: OK
[]

Questions

get
List questions

https://api.weglot.com
/public/questions
This endpoint returns most commonly asked questions.
Request
Response
Headers
Content-Type
optional
string
application/json
Query Parameters
offset
optional
integer
The offset to apply
limit
optional
integer
The maximum number of questions to return
search
optional
string
The word or expression to search
200: OK
[
{
"id": 1,
"subject": "Not translating - 404 Not Found Error",
"tags": "setup, wordpress",
"created_at "1523371935"
"preview": "Hi, I add my API key and go on my website to try changing language but when I click on « EN » this page appear : Not Found The requested URL /en/ was not found on this server..."
},
{
"id": 2,
"subject": "Integrating Javascript - exclude some part",
"tags": "javascript,pbedition",
"created_at": "1523372268",
"preview": "Hi, I am integrating your translation tool with my site but want to stop translations of specific blocks of text, I wanted to use the css class to do this but I cant work out how to do this...."
},
...
]

get
Show a question

https://api.weglot.com
/public/questions/id
This endpoint returns complete informations about a question.
Request
Response
Path Parameters
id
required
integer
The id of the question
Headers
Content-Type
optional
string
application/json
200: OK
{
"id": 1,
"subject": "Not translating - 404 Not found error",
"tags": "setup,wordpress",
"created_at": "1523371935",
"support_conversations_messages": [
{
"id": 1,
"message": "Hi,\r\n\r\nI add my API key and go on my website to try changing language but when I click on « EN » this page appear :\r\n\r\nNot Found\r\n\r\nThe requested URL /en/ was not found on this server.\r\n\r\nOriginal language : French\r\nDestination Language : English\r\n\r\nThanks",
"sender_name": "Kierin",
"created_at": "1522965388"
},
{
"id": 2,
"message": "Hi,\r\n\r\nThanks for your message.\r\n\r\nIt seems to be a Permalinks issue. To fix it:\r\n1. Go to your WordPress admin, in Settings > Permalinks\r\n2. Select anything but NOT the first choice (\"plain\") and make sure you don't have /index.php in your URLs.\r\n3. Save your changes\r\n4. Refresh your web page and it should be working\r\n\r\nLet me know if you need help with it.\r\nHave a nice day,",
"sender_name": "",
"created_at": "1523001482"
},
{
"id": 3,
"message": "Hi, sorry I forgot to answer, everything is ok ! Thank you :)",
"sender_name": "Kierin",
"created_at": "1523271890"
}
],
"preview": "Hi,\r\n\r\nI add my API key and go on my website to try changing language but when I click on « EN » this page appear :\r\n\r\nNot Found\r\n\r\nThe requested URL /en/ was not found on this server.\r\n\r\n..."
}

Languages

get
List languages

https://api.weglot.com
/public/languages
This endpoint returns all availaible languages.
Request
Response
Headers
Content-Type
optional
string
application/json
200: OK
[
{
"code": "af",
"local_name": "Afrikaans",
"english_name": "Afrikaans"
},
{
"code": "ar",
"local_name": "العربية\u200f",
"english_name": "Arabic"
},
{
"code": "az",
"local_name": "Azərbaycan dili",
"english_name": "Azerbaijani"
},
{
"code": "be",
"local_name": "Беларуская",
"english_name": "Belarusian"
},
{
"code": "bg",
"local_name": "български",
"english_name": "Bulgarian"
},
...
]

get
Is language pair supported

https://api.weglot.com
/public/languages/is-supported
Request
Response
Headers
Content-Type
optional
string
application/json
Query Parameters
languageTo
required
string
The language you wish to translate to
languageFrom
required
string
The original language
200: OK
{
"is_supported": true
}

Authenticated Endpoints

Authentification

Weglot requires an API key to allow access to its endpoints. You can register and get a Weglot API Key at: Register.

The API key is to be included in all API requests to the server in the URL as the value of the api_key parameter, as follows:

https://api.weglot.com/endpoint?api_key=my_api_key

Make sure to replace my_api_key with your Weglot API key.

post
Translate

https://api.weglot.com
/translate
This endpoint retrieves all translations. It takes an array of sentences in an original language in input and outputs the same array of sentences but translated in another language. The body is sent in the JSON format
Request
Response
Headers
Content-Type
optional
string
application/json
Query Parameters
api_key
required
string
Your Weglot API Key
Body Parameters
l_from
required
string
ISO 639-1 code of the original language
l_to
required
string
ISO 639-1 code of the destination language
words
required
array
Sentences in original language
words[t]
required
integer
Type of the word based on WordType resource
words[w]
required
string
Sentence to translate
bot
optional
integer
Link to user agent based on BotType resource
request_url
required
string
URL where the request come from
title
optional
string
Title of the page where these sentences come from
200: OK
Usual return with two basic sentences:
{
"l_from":"en",
"l_to":"fr",
"title":"My awesome page",
"request_url":"https:\/\/www.website.com\/",
"bot":0,
"from_words":[
"This is a blue car",
"This is a black car"
],
"to_words":[
"C'est une voiture bleue",
"C'est une voiture noire"
]
}

You can find WordType and BotType resources at the end of this document.

Here is a simple request example:

HTTP
cURL
POST /translate?api_key=my_api_key HTTP/1.1
Host: api.weglot.com
Content-Type: application/json
{
"l_from":"en",
"l_to":"fr",
"request_url":"https://www.website.com/",
"words":[
{"w":"This is a blue car", "t": 1},
{"w":"This is a black car", "t": 1}
]
}
curl -X POST \
'https://api.weglot.com/translate?api_key=my_api_key' \
-H 'Content-Type: application/json' \
-d '{
"l_from":"en",
"l_to":"fr",
"request_url":"https://www.website.com/",
"words":[
{"w":"This is a blue car", "t": 1},
{"w":"This is a black car", "t": 1}
]
}'

No content is returned by this endpoint, you will only get a 200 status code if the service is up and running.

This is only a health check endpoint, don't spam it.

Resources

BotType

Used to define the source of a request.

Short-Name

Value

Description

HUMAN

0

Sent from human action

OTHER

1

Sent from unknown source

GOOGLE

2

Sent from Google Bot

BING

3

Sent from Bing Bot

YAHOO

4

Sent from Yahoo Bot

BAIDU

5

Sent from Baidu Bot

YANDEX

6

Sent from Yandex Bot

WordType

Used to provide context over where the text we wish to translate comes from. Any general text node is of WordType 1. We use the WordType to classify translations on the admin dashboard.

Short name

Value

Description

OTHER

0

None of the elements below (deprecated)

TEXT

1

General text (used most of the time)

VALUE

2

The value of an input tag'svalueattribute

PLACEHOLDER

3

The value of an input tag's placeholderattribute

META_CONTENT

4

The value of a meta tags' content attribute

IFRAME_SRC

5

The src link to a page used in an iframe

IMG_SRC

6

The srcvalue of an imgtag

IMG_ALT

7

The alt value of an imgtag

PDF_HREF

8

A URL pointing to a PDF document