Google Cloud Translation

텍스트를 번역하고 언어를 감지하기 위해 Google Cloud Translation v3 gRPC API를 호출하는 형식화된 인터페이스입니다.

소개

Google Cloud Translation은 언어 간에 텍스트를 번역하며 원본 언어를 자동으로 감지할 수 있습니다. gRPC API는 google.cloud.translation.v3.TranslationService 서비스를 통해 제공되며, TLS를 통해 translate.googleapis.com:443에서 접근하고, 주요 메서드는 TranslateText, DetectLanguageGetSupportedLanguages입니다.

요청은 TsgcGRPCTranslationTranslateTextRequest로 작성되며, 이는 Parent(projects/<id>/locations/global), Contents, SourceLanguageCode 및 TargetLanguageCode를 설정합니다. 응답은 TsgcGRPCTranslationTranslateTextResponse로 반환되며, 그 Translations에는 TranslatedText가 포함됩니다.

아래 예제는 서비스 계정 JWT로 인증하고, Translation 호스트에 대해 TsgcHTTP2Client 위에 TsgcGRPCClient를 연결하고, authorization Bearer 메타데이터를 설정한 후, "Hello, world!"를 en에서 es로 번역하기 위해 TranslateText를 호출합니다.


    TsgcHTTP2Client *oHTTP2 = new TsgcHTTP2Client();
    oHTTP2->Host = "translate.googleapis.com";
    oHTTP2->Port = 443;
    oHTTP2->TLS = true;

    TsgcGRPCClient *oGRPC = new TsgcGRPCClient();
    oGRPC->Client = oHTTP2;

    // service-account JWT authentication
    oGRPC->GoogleCloudOptions->JWT->KeyFile = "service-account.json";
    oGRPC->GoogleCloudOptions->JWT->API_Endpoint = "https://translate.googleapis.com/";
    oGRPC->DefaultMetadata->AddValue("authorization", "Bearer " + oGRPC->GoogleCloudOptions->JWT->Token);

    // build the typed request and call the method
    TsgcGRPCTranslationTranslateTextRequest *oRequest = new TsgcGRPCTranslationTranslateTextRequest();
    oRequest->Parent = "projects/my-project-id/locations/global";
    oRequest->Contents->Add("Hello, world!");
    oRequest->SourceLanguageCode = "en";
    oRequest->TargetLanguageCode = "es";
    TsgcGRPCResponse *oResponse = oGRPC->Call("google.cloud.translation.v3.TranslationService", "TranslateText", oRequest->ToBytes());
    ShowMessage(oResponse->DataString);
    delete oRequest;

Methods

Name설명
TranslateText하나 이상의 텍스트 문자열을 원본 언어에서 대상 언어로 번역합니다.
DetectLanguage제공된 텍스트의 언어를 감지합니다.
GetSupportedLanguages번역에 지원되는 언어 목록을 반환합니다.

Demo

작동하는 샘플은 데모 폴더 Demos/21.GRPC/12.Translation에서 제공되며, TranslateText 메서드로 인증하고 텍스트를 번역하는 방법을 보여줍니다.

참조