async function translateText(
    text,
    sourceLanguageCode,
    targetLanguageCode,
    projectId,
    glossaryName
  ) {
    // Instantiates a client
    const translationClient = new translate.TranslationServiceClient();
    const glossary = translationClient.glossaryPath(
      projectId,
      'us-central1',
      glossaryName
    );
    const glossaryConfig = {
      glossary: glossary,
    };
    // Construct request
    const request = {
      parent: translationClient.locationPath(projectId, 'us-central1'),
      contents: [text],
      mimeType: 'text/plain', // mime types: text/plain, text/html
      sourceLanguageCode: sourceLanguageCode,
      targetLanguageCode: targetLanguageCode,
      glossaryConfig: glossaryConfig,
    };

    // Run request
    const [response] = await translationClient.translateText(request);
    // Extract the string of translated text
    return response.glossaryTranslations[0].translatedText;
  }
Translates text to a given language using a glossary

ARGS
text: String of text to translate
sourceLanguageCode: language of input text
targetLanguageCode: language of output text
projectId: GCP project id
glossaryName: name you gave your project's glossary
    resource when you created it
RETURNS
String of translated text