/// <summary>Snippet for CreateGlossary</summary>
        public void CreateGlossary_RequestObject()
        {
            // Snippet: CreateGlossary(CreateGlossaryRequest,CallSettings)
            // Create client
            TranslationServiceClient translationServiceClient = TranslationServiceClient.Create();
            // Initialize request argument(s)
            CreateGlossaryRequest request = new CreateGlossaryRequest
            {
                ParentAsLocationName = new LocationName("[PROJECT]", "[LOCATION]"),
                Glossary             = new Glossary(),
            };
            // Make the request
            Operation <Glossary, CreateGlossaryMetadata> response =
                translationServiceClient.CreateGlossary(request);

            // Poll until the returned long-running operation is complete
            Operation <Glossary, CreateGlossaryMetadata> completedResponse =
                response.PollUntilCompleted();
            // Retrieve the operation result
            Glossary result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            Operation <Glossary, CreateGlossaryMetadata> retrievedResponse =
                translationServiceClient.PollOnceCreateGlossary(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Glossary retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
Example #2
0
        public string CreateGlossary(string glossaryId, string inputUri)
        {
            try
            {
                var request = new CreateGlossaryRequest
                {
                    ParentAsLocationName = new LocationName(projectId, locaionId),
                    Parent   = new LocationName(projectId, locaionId).ToString(),
                    Glossary = new Glossary
                    {
                        Name             = new GlossaryName(projectId, locaionId, glossaryId).ToString(),
                        LanguageCodesSet = new Glossary.Types.LanguageCodesSet
                        {
                            LanguageCodes = { "en", "ko", },
                        },
                        InputConfig = new GlossaryInputConfig
                        {
                            GcsSource = new GcsSource {
                                InputUri = inputUri,
                            },
                        },
                    },
                };

                Glossary response = client.CreateGlossary(request).PollUntilCompleted().Result;
                return($"name: {response.Name}, Entry count: {response.EntryCount}, Input URI: {response.InputConfig.GcsSource.InputUri}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }
        /// <summary>
        /// Create Glossary.
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project ID.</param>
        /// <param name="glossaryId">Glossary ID.</param>
        /// <param name="inputUri">Google Cloud Storage URI where glossary is stored in csv format.</param>
        public static void CreateGlossarySample(string projectId  = "[Google Cloud Project ID]",
                                                string glossaryId = "[YOUR_GLOSSARY_ID]",
                                                string inputUri   = "gs://cloud-samples-data/translation/glossary_ja.csv")
        {
            TranslationServiceClient translationServiceClient = TranslationServiceClient.Create();
            CreateGlossaryRequest    request = new CreateGlossaryRequest
            {
                ParentAsLocationName = new LocationName(projectId, "us-central1"),
                Parent   = new LocationName(projectId, "us-central1").ToString(),
                Glossary = new Glossary
                {
                    Name             = new GlossaryName(projectId, "us-central1", glossaryId).ToString(),
                    LanguageCodesSet = new Glossary.Types.LanguageCodesSet
                    {
                        LanguageCodes =
                        {
                            "en", // source lang
                            "ja", // target lang
                        },
                    },
                    InputConfig = new GlossaryInputConfig
                    {
                        GcsSource = new GcsSource
                        {
                            InputUri = inputUri,
                        },
                    },
                },
            };
            // Poll until the returned long-running operation is complete
            Glossary response = translationServiceClient.CreateGlossary(request).PollUntilCompleted().Result;

            Console.WriteLine("Created Glossary.");
            Console.WriteLine($"Glossary name: {response.Name}");
            Console.WriteLine($"Entry count: {response.EntryCount}");
            Console.WriteLine($"Input URI: {response.InputConfig.GcsSource.InputUri}");
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreateGlossaryRequest request;

            try
            {
                request = new CreateGlossaryRequest
                {
                    CatalogId             = CatalogId,
                    CreateGlossaryDetails = CreateGlossaryDetails,
                    OpcRequestId          = OpcRequestId,
                    OpcRetryToken         = OpcRetryToken
                };

                response = client.CreateGlossary(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Glossary);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }