forked from watson-developer-cloud/unity-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleLanguageTranslatorV3.cs
More file actions
74 lines (65 loc) · 2.31 KB
/
ExampleLanguageTranslatorV3.cs
File metadata and controls
74 lines (65 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using IBM.Watson.LanguageTranslator.V3;
using IBM.Watson.LanguageTranslator.V3.Model;
using IBM.Cloud.SDK.Utilities;
using IBM.Cloud.SDK.Authentication;
using IBM.Cloud.SDK.Authentication.Iam;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using IBM.Cloud.SDK;
public class ExampleLanguageTranslatorV3 : MonoBehaviour
{
#region PLEASE SET THESE VARIABLES IN THE INSPECTOR
[Space(10)]
[Tooltip("The IAM apikey.")]
[SerializeField]
private string iamApikey;
[Tooltip("The service URL (optional). This defaults to \"https://gateway.watsonplatform.net/discovery/api\"")]
[SerializeField]
private string serviceUrl;
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
[SerializeField]
private string versionDate;
#endregion
private LanguageTranslatorService service;
// Start is called before the first frame update
void Start()
{
LogSystem.InstallDefaultReactors();
Runnable.Run(CreateService());
}
// Update is called once per frame
public IEnumerator CreateService()
{
if (string.IsNullOrEmpty(iamApikey))
{
throw new IBMException("Plesae provide IAM ApiKey for the service.");
}
// Create credential and instantiate service
IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);
// Wait for tokendata
while (!authenticator.CanAuthenticate())
yield return null;
service = new LanguageTranslatorService(versionDate, authenticator);
if (!string.IsNullOrEmpty(serviceUrl))
{
service.SetServiceUrl(serviceUrl);
}
Log.Debug("LanguageTranslatorServiceV3", "ListModels result");
}
private IEnumerator ExampleListModels()
{
TranslationModels listModelsResponse = null;
service.ListModels(
callback: (DetailedResponse<TranslationModels> response, IBMError error) =>
{
Log.Debug("LanguageTranslatorServiceV3", "ListModels result: {0}", response.Response);
listModelsResponse = response.Result;
},
source: "en",
target: "fr"
);
while (listModelsResponse == null)
yield return null;
}
}