Display an error message when the Web request to the Translator service fails.
This commit is contained in:
parent
0953dd1d16
commit
eef37a69af
@ -32,6 +32,8 @@
|
||||
<system:String x:Key="TranslatorLocationPrompt">This is typically the Global region, but could also be a single Azure region.</system:String>
|
||||
<system:String x:Key="NothingToTranslate">Please select at least one language before you translate the metadata.</system:String>
|
||||
<system:String x:Key="UnableToTranslate">Microsoft Translator was unable to translate the metadata strings into {0}. Please try again later or remove this language from the translation.</system:String>
|
||||
<system:String x:Key="UnableToAccessTranslatorEndpoint">Microsoft Translator was unable to translate the metadata strings because of a Web request error. Make sure the Microsoft Translator configuration settings are correct and check your network connection.</system:String>
|
||||
<system:String x:Key="WebRequestError">Web Request Error</system:String>
|
||||
<system:String x:Key="ExportHeading">Export .csv files</system:String>
|
||||
<system:String x:Key="ExportDescription">You can export the metadata captions, descriptions, and display folder strings into .csv files based on the locale identifiers (LCIDs) of the selected languages. Metadata Translator creates a separate .csv file for each LCID.</system:String>
|
||||
<system:String x:Key="ExportFolderDescription">Select the folder where you want to store your .csv files. Note that Metadata Translator might overwrite any existing files in this folder.</system:String>
|
||||
|
@ -7,6 +7,7 @@ using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Windows;
|
||||
|
||||
namespace Metadata_Translator
|
||||
{
|
||||
@ -111,6 +112,8 @@ namespace Metadata_Translator
|
||||
/// Translate the batch and assign the translated strings to the target languages.
|
||||
///
|
||||
var translatedStrings = TranslateBatch(translationBatch, translationId);
|
||||
if (translatedStrings.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < maxBatchSize; i++)
|
||||
{
|
||||
foreach (Language language in targetLanguages)
|
||||
@ -121,6 +124,7 @@ namespace Metadata_Translator
|
||||
|
||||
Translate(dataRows, targetLanguages, translationId, replaceExistingTranslations, ++iterationId);
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> TranslateBatch(List<object> sourceObjects, string targetLanguage)
|
||||
{
|
||||
@ -143,6 +147,18 @@ namespace Metadata_Translator
|
||||
HttpResponseMessage response = client.SendAsync(request).Result;
|
||||
string result = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
/// Display an error message if the Web request was not successful.
|
||||
///
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
MessageBox.Show(
|
||||
Application.Current.FindResource("UnableToAccessTranslatorEndpoint") as string,
|
||||
Application.Current.FindResource("WebRequestError") as string,
|
||||
MessageBoxButton.OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/// Parse the results and add the strings to the translated phrases if there was no error,
|
||||
/// i.e. the target language was returned together with the translated string, which is
|
||||
/// not the case if the service gives back an error message.
|
||||
@ -156,6 +172,7 @@ namespace Metadata_Translator
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return translatedPhrases;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user