PHP Classes

File: examples/language/LanguageTranslator.php

Recommend this page to a friend!
  Classes of MERAJ AHMAD SIDDIQUI  >  PHP IBM Watson  >  examples/language/LanguageTranslator.php  >  Download  
File: examples/language/LanguageTranslator.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP IBM Watson
Call IBM Watson API services
Author: By
Last change:
Date: 1 month ago
Size: 1,328 bytes


Class file image Download

include dirname(dirname(__DIR__)) . "/vendor/autoload.php";
//Provide jspn file to config
use IBMWatson\Config;
//json file containing url, username and password for the service
$api_credintial_json_file = dirname(dirname(__DIR__)) . "/config/language_translator.json";
$config = Config::init($api_credintial_json_file);

 * Providing config to Translator
 * @var Translator
$translator = new Translator($config);

$language_supported = $translator->getSupportedLanguage();

$language_set = [
"from" => "en",
"to" => "es",

$text = "PHP Developer, I code to change the world's work flow";

$translated = $translator->translate($text);
//all models
$models = $translator->listModels();
//conversationa Models
$conver_models = $translator->listConversationalModels();

//Creating new model
 * Creating a new model requires a glossary to used by watson
 * a tmx file (Translation Memory Echange ) by which the translation will work
 * a sample tms file is provided

$glossary_tmx = "custom_model.tmx";
$new_model_details = [
"name" => "custom-englis-to-bhojpuri",
"base_model_id" => "en-es",
"glossary" => $glossary_tmx,

$new_model = $translator->createModel($new_model_details);