curl --request POST \
--url https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"source_locale_code": "en",
"target_locale_code": "de",
"service": "google_translate"
}
'import requests
url = "https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings"
payload = {
"source_locale_code": "en",
"target_locale_code": "de",
"service": "google_translate"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
source_locale_code: 'en',
target_locale_code: 'de',
service: 'google_translate'
})
};
fetch('https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'source_locale_code' => 'en',
'target_locale_code' => 'de',
'service' => 'google_translate'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings"
payload := strings.NewReader("{\n \"source_locale_code\": \"en\",\n \"target_locale_code\": \"de\",\n \"service\": \"google_translate\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"source_locale_code\": \"en\",\n \"target_locale_code\": \"de\",\n \"service\": \"google_translate\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"source_locale_code\": \"en\",\n \"target_locale_code\": \"de\",\n \"service\": \"google_translate\"\n}"
response = http.request(request)
puts response.read_body{
"source_locale_code": "en",
"target_locale_code": "de",
"service": "google_translate"
}{
"message": "Validation Failed",
"errors": [
{
"resource": "Resource",
"field": "name",
"message": "can't be blank"
}
]
}Create a locale provider mapping
Creates a locale-pair-specific machine translation provider override for the account. When a mapping exists for a given source/target locale pair, that provider is used instead of the account default. Only one mapping may exist per source/target locale pair; attempting to create a duplicate returns a validation error. The source and target locale codes must differ.
curl --request POST \
--url https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"source_locale_code": "en",
"target_locale_code": "de",
"service": "google_translate"
}
'import requests
url = "https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings"
payload = {
"source_locale_code": "en",
"target_locale_code": "de",
"service": "google_translate"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
source_locale_code: 'en',
target_locale_code: 'de',
service: 'google_translate'
})
};
fetch('https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'source_locale_code' => 'en',
'target_locale_code' => 'de',
'service' => 'google_translate'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings"
payload := strings.NewReader("{\n \"source_locale_code\": \"en\",\n \"target_locale_code\": \"de\",\n \"service\": \"google_translate\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"source_locale_code\": \"en\",\n \"target_locale_code\": \"de\",\n \"service\": \"google_translate\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.phrase.com/v2/accounts/{account_id}/machine_translation_locale_provider_mappings")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"source_locale_code\": \"en\",\n \"target_locale_code\": \"de\",\n \"service\": \"google_translate\"\n}"
response = http.request(request)
puts response.read_body{
"source_locale_code": "en",
"target_locale_code": "de",
"service": "google_translate"
}{
"message": "Validation Failed",
"errors": [
{
"resource": "Resource",
"field": "name",
"message": "can't be blank"
}
]
}Authorizations
Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.
Headers
Two-Factor-Authentication token (optional)
Path Parameters
Account ID
Body
The locale code of the source language (e.g. "en").
"en"
The locale code of the target language (e.g. "de"). Must differ from source_locale_code.
"de"
The machine translation service to use for this locale pair. Must be a service enabled for the account.
"google_translate"
Response
Created
The locale code of the source language for this mapping.
"en"
The locale code of the target language for this mapping.
"de"
The translation service applied when translating from source to target locale.
"google_translate"
Was this page helpful?