/// <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 }
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); } }
public void CreateGoogleGlossary(LanguagePair[] languagePairs) { try { if (!string.IsNullOrEmpty(_options.GlossaryPath)) { Glossary glossary; if (_options.BasicCsv) { var sourceLang = languagePairs[0].SourceCultureName; var targetLang = languagePairs[0].TargetCultureName; glossary = CreateUnidirectionalCsvGlossary(sourceLang, targetLang); } else { var glossaryLanguages = GetGlossaryLanguages(languagePairs); glossary = CreatetCsvGlossary(glossaryLanguages); } var glossaryResponse = _translationServiceClient.CreateGlossary( new LocationName(_options.ProjectName, _options.ProjectLocation).ToString(), glossary); } } catch (Exception e) { _logger.Error($"{MethodBase.GetCurrentMethod().Name}: {e}"); } }
/// <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}"); }