Languages
Multilingual support in Clarifai
The Clarifai API supports many languages in addition to English. These are represented as translations of names of concepts so that when you search by concept name or get predictions from a model's concepts, you can utilize the language of your choice.
Supported Languages
The currently supported languages are listed below.
Language | Code |
---|---|
Arabic (ar) | ar |
Bengali (bn) | bn |
Danish (da) | da |
German (de) | de |
English (en) | en |
Spanish (es) | es |
Finnish (fi) | fi |
French (fr) | fr |
Hindi (hi) | hi |
Hungarian (hu) | hu |
Italian (it) | it |
Japanese (ja) | ja |
Korean (ko) | ko |
Dutch (nl) | nl |
Norwegian (no) | no |
Punjabi (pa) | pa |
Polish (pl) | pl |
Portuguese (pt) | pt |
Russian (ru) | ru |
Swedish (sv) | sv |
Turkish (tr) | tr |
Chinese Simplified (zh) | zh |
Chinese Traditional (zh-TW) | zh-TW |
Default Language
When you create a new application, you can specify a default language. This will be the default language concepts are returned in when you do not explicitly set a language in an API request.
You cannot change the default language. You can, however, contact us to change the language.
List Language Translations by Concept ID
You can see all the language translations for a given concept ID with a GET call. This call supports pagination.
Below is an example of how you would list language translations by concept ID.
The initialization code used in the following examples is outlined in detail on the client installation page.
- gRPC Python
- JavaScript (REST)
- gRPC NodeJS
- gRPC Java
- gRPC PHP
- cURL
#############################################################################
# In this section, we set the user authentication, app ID, and concept ID.
# Change these strings to run your own example.
#############################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change this to whatever concept you want to see its languages
CONCEPT_ID = 'cat'
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
list_concept_languages_response = stub.ListConceptLanguages(
service_pb2.ListConceptLanguagesRequest(
user_app_id=userDataObject,
concept_id=CONCEPT_ID
),
metadata=metadata
)
if list_concept_languages_response.status.code != status_code_pb2.SUCCESS:
print(list_concept_languages_response.status)
raise Exception("List concept failed, status: " + list_concept_languages_response.status.description)
print(list_concept_languages_response)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
//Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever concept you want to see its languages
const CONCEPT_ID = 'cat';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
};
fetch("https://api.clarifai.com/v2/users/" + USER_ID + "/apps/" + APP_ID + "/concepts/" + CONCEPT_ID + "/languages", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change this to whatever concept you want to see its languages
const CONCEPT_ID = 'cat';
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListConceptLanguages(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
concept_id: CONCEPT_ID
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List concepts failed, status: " + response.status.description);
}
for (const languages of response.concept_languages) {
console.log(languages)
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change this to whatever concept you want to see its languages
static final String CONCEPT_ID = "charlie";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiConceptLanguageResponse listConceptLanguagesResponse = stub.listConceptLanguages(
ListConceptLanguagesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setConceptId(CONCEPT_ID)
.build()
);
if (listConceptLanguagesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List concept languages failed, status: " + listConceptLanguagesResponse.getStatus());
}
System.out.println(listConceptLanguagesResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, and concept ID.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change this to whatever concept you want to see its languages
$CONCEPT_ID = "cat";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListConceptLanguagesRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListConceptLanguages(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListConceptLanguagesRequest([
"user_app_id" => $userDataObject,
"concept_id" => $CONCEPT_ID
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
print $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_CONCEPT_ID_HERE/languages" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
Raw Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "e3d3b16eccf82d3b5563a0a01eebc579"
}
concept_languages {
id: "en"
name: "Cat Name"
}
Get Specific Language Translation for a Concept
Below is an example of how to get a single language translation for a concept. You can get it by the language code and concept ID.
- gRPC Python
- JavaScript (REST)
- gRPC NodeJS
- gRPC Java
- gRPC PHP
- cURL
#######################################################################################
# In this section, we set the user authentication, app ID, concept ID and language.
# Change these strings to run your own example.
#######################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever concept you want to get its language translation
CONCEPT_ID = 'cat'
CONCEPT_LANGUAGE = "en"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
get_concept_language_response = stub.GetConceptLanguage(
service_pb2.GetConceptLanguageRequest(
user_app_id=userDataObject,
concept_id=CONCEPT_ID,
language=CONCEPT_LANGUAGE
),
metadata=metadata
)
if get_concept_language_response.status.code != status_code_pb2.SUCCESS:
print(get_concept_language_response.status)
raise Exception("Get concept failed, status: " + get_concept_language_response.status.description)
print(get_concept_language_response)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID and language.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
//Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to get its language translation
const CONCEPT_ID = 'cat';
const CONCEPT_LANGUAGE = "en";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
};
fetch("https://api.clarifai.com/v2/users/" + USER_ID + "/apps/" + APP_ID + "/concepts/" + CONCEPT_ID + "/languages/" + CONCEPT_LANGUAGE, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID and language.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to get its language translation
const CONCEPT_ID = 'cat';
const CONCEPT_LANGUAGE = "en";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.GetConceptLanguage(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
concept_id: CONCEPT_ID,
language: CONCEPT_LANGUAGE
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Get concepts failed, status: " + response.status.description);
}
console.log(response.concept_language);
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID and language.
// Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to get its language translation
static final String CONCEPT_ID = "charlie";
static final String CONCEPT_LANGUAGE = "ja";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
SingleConceptLanguageResponse getConceptLanguageResponse = stub.getConceptLanguage(
GetConceptLanguageRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setConceptId(CONCEPT_ID)
.setLanguage(CONCEPT_LANGUAGE)
.build()
);
if (getConceptLanguageResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Get concept languages failed, status: " + getConceptLanguageResponse.getStatus());
}
System.out.println(getConceptLanguageResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID and language.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to get its language translation
$CONCEPT_ID = 'cat';
$CONCEPT_LANGUAGE = "en";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\GetConceptLanguageRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->GetConceptLanguage(
// The request object carries the request along with the request status and other metadata related to the request itself
new GetConceptLanguageRequest([
"user_app_id" => $userDataObject,
"concept_id" => $CONCEPT_ID,
"language" => $CONCEPT_LANGUAGE
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
print $response->serializeToJsonString();
?>
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_CONCEPT_ID_HERE/languages/LANGUAGE_ID_HERE" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
Raw Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "ef625131675ba87841983c6e7f654e39"
}
concept_language {
id: "en"
name: "Cat Name"
}
Add a Language Translation for a Concept
Below is an example of how to create a language translation for a concept by POSTing that language translation.
- gRPC Python
- JavaScript (REST)
- gRPC NodeJS
- gRPC Java
- gRPC PHP
- cURL
################################################################################################
# In this section, we set the user authentication, app ID, concept ID, and language ID and name.
# Change these strings to run your own example.
################################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever concept you want to add its language translation
CONCEPT_ID = 'charlie'
LANGUAGE_ID = "ja"
LANGUAGE_NAME = "ボスコ"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
get_concept_language_response = stub.PostConceptLanguages(
service_pb2.PostConceptLanguagesRequest(
user_app_id=userDataObject,
concept_id=CONCEPT_ID,
concept_languages=[resources_pb2.ConceptLanguage(
id=LANGUAGE_ID,
name=LANGUAGE_NAME
)]
),
metadata=metadata
)
if get_concept_language_response.status.code != status_code_pb2.SUCCESS:
print(get_concept_language_response.status)
raise Exception("Get concept failed, status: " + get_concept_language_response.status.description)
print(get_concept_language_response)
<!--index.html file-->
<script>
///////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID and name.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to add its language translation
const CONCEPT_ID = 'charlie';
const LANGUAGE_ID = "ja";
const LANGUAGE_NAME = "ボスコ";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"concept_languages": [
{
"id": LANGUAGE_ID,
"name": LANGUAGE_NAME
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/concepts/" + CONCEPT_ID + "/languages", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID and name.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to add its language translation
const CONCEPT_ID = 'charlie';
const LANGUAGE_ID = "ja";
const LANGUAGE_NAME = "ボスコ";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostConceptLanguages(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
concept_id: CONCEPT_ID,
concept_languages: [
{
id: LANGUAGE_ID,
name: LANGUAGE_NAME
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Get concepts failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID and name.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to add its language translation
static final String CONCEPT_ID = "charlie";
static final String LANGUAGE_ID = "ja";
static final String LANGUAGE_NAME = "ボスコ";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiConceptLanguageResponse postConceptLanguageResponse = stub.postConceptLanguages(
PostConceptLanguagesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setConceptId(CONCEPT_ID)
.addConceptLanguages(ConceptLanguage.newBuilder().setId(LANGUAGE_ID).setName(LANGUAGE_NAME))
.build()
);
if (postConceptLanguageResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post concept languages failed, status: " + postConceptLanguageResponse.getStatus());
}
System.out.println(postConceptLanguageResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
///////////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID and name.
// Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to add its language translation
$CONCEPT_ID = "charlie";
$LANGUAGE_ID = "ja";
$LANGUAGE_NAME = "ボスコ";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostConceptLanguagesRequest;
use Clarifai\Api\ConceptLanguage;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostConceptLanguages(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostConceptLanguagesRequest([
"user_app_id" => $userDataObject,
"concept_id" => $CONCEPT_ID,
"concept_languages" => [
new ConceptLanguage([
"id" => $LANGUAGE_ID,
"name" => $LANGUAGE_NAME
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
print $response->serializeToJsonString();
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_CONCEPT_ID_HERE/languages" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"concept_languages": [
{
"id": "LANGUAGE_ID_HERE",
"name": "LANGUAGE_NAME_HERE"
}
]
}'
Raw Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "c5054cc812539059340a2275c3cb7cd5"
}
concept_languages {
id: "ja"
name: "\343\203\234\343\202\271\343\202\263"
}
Update a Language Translation for a Concept
Below is an example of how to update a language translation for a concept by PATCHing that language translation.
- gRPC Python
- JavaScript (REST)
- gRPC NodeJS
- gRPC Java
- gRPC PHP
- cURL
########################################################################################
# In this section, we set the user authentication, app ID, concept ID, and language ID
# and new name. Change these strings to run your own example.
########################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever concept you want to update its language translation
CONCEPT_ID = 'charlie'
LANGUAGE_ID = "ja"
LANGUAGE_NAME = "new name"
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)
get_concept_language_response = stub.PatchConceptLanguages(
service_pb2.PatchConceptLanguagesRequest(
user_app_id=userDataObject,
concept_id=CONCEPT_ID,
concept_languages=[resources_pb2.ConceptLanguage(
id=LANGUAGE_ID,
name=LANGUAGE_NAME
)],
action="overwrite"
),
metadata=metadata
)
if get_concept_language_response.status.code != status_code_pb2.SUCCESS:
print(get_concept_language_response.status)
raise Exception("Get concept failed, status: " + get_concept_language_response.status.description)
print(get_concept_language_response)
<!--index.html file-->
<script>
/////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID
// and new name. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to update its language translation
const CONCEPT_ID = 'charlie';
const LANGUAGE_ID = "ja";
const LANGUAGE_NAME = "new name";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"concept_languages": [
{
"id": LANGUAGE_ID,
"name": LANGUAGE_NAME
}
],
"action": "overwrite"
});
const requestOptions = {
method: 'PATCH',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/concepts/" + CONCEPT_ID + "/languages", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
/////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID
// and new name. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to update its language translation
const CONCEPT_ID = 'charlie';
const LANGUAGE_ID = "ja";
const LANGUAGE_NAME = "new name";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PatchConceptLanguages(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
action: "overwrite",
concept_id: CONCEPT_ID,
concept_languages: [
{
id: LANGUAGE_ID,
name: LANGUAGE_NAME
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Get concepts failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID
// and new name. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to update its language translation
static final String CONCEPT_ID = "charlie";
static final String LANGUAGE_ID = "ja";
static final String LANGUAGE_NAME = "new name";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiConceptLanguageResponse patchConceptLanguageResponse = stub.patchConceptLanguages(
PatchConceptLanguagesRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID))
.setAction("overwrite")
.setConceptId(CONCEPT_ID)
.addConceptLanguages(ConceptLanguage.newBuilder().setId(LANGUAGE_ID).setName(LANGUAGE_NAME))
.build()
);
if (patchConceptLanguageResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Update concept languages failed, status: " + patchConceptLanguageResponse.getStatus());
}
System.out.println(patchConceptLanguageResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
/////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and language ID
// and new name. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to update its language translation
$CONCEPT_ID = "charlie";
$LANGUAGE_ID = "ja";
$LANGUAGE_NAME = "new name";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PatchConceptLanguagesRequest;
use Clarifai\Api\ConceptLanguage;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PatchConceptLanguages(
// The request object carries the request along with the request status and other metadata related to the request itself
new PatchConceptLanguagesRequest([
"user_app_id" => $userDataObject,
"concept_id" => $CONCEPT_ID,
"concept_languages" => [
new ConceptLanguage([
"id" => $LANGUAGE_ID,
"name" => $LANGUAGE_NAME
])
],
"action" => "overwrite"
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
print $response->serializeToJsonString();
?>
curl -X PATCH "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_CONCEPT_ID_HERE/languages" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
-d '{
"concept_languages": [
{
"id": "LANGUAGE_ID_HERE",
"name": "LANGUAGE_NAME_HERE"
}
],
"action": "overwrite"
}'
Raw Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "779d702cbb303bcce4e469eb1d3552c2"
}
concept_languages {
id: "ja"
name: "new name"
}