code: static TranslateTextResponse translateTextWithGlossary(
        String projectId,
        String location,
        String name,
        String text,
        String sourceLanguageCode,
        String targetLanguageCode) {
      try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
  
        LocationName locationName =
            LocationName.newBuilder().setProject(projectId).setLocation(location).build();
        GlossaryName glossaryName =
            GlossaryName.newBuilder()
                .setProject(projectId)
                .setLocation(location)
                .setGlossary(name)
                .build();
        TranslateTextGlossaryConfig translateTextGlossaryConfig =
            TranslateTextGlossaryConfig.newBuilder().setGlossary(glossaryName.toString()).build();
        TranslateTextRequest translateTextRequest =
            TranslateTextRequest.newBuilder()
                .setParent(locationName.toString())
                .setMimeType("text/plain")
                .setSourceLanguageCode(sourceLanguageCode)
                .setTargetLanguageCode(targetLanguageCode)
                .addContents(text)
                .setGlossaryConfig(translateTextGlossaryConfig)
                .build();
  
        // Call the API
        TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
        System.out.format(
            "Translated text: %s", response.getTranslationsList().get(0).getTranslatedText());
        return response;
  
      } catch (Exception e) {
        throw new RuntimeException("Couldn't create client.", e);
      }
    }
docs: [START translate_translate_text_with_glossary_beta]