Translate error messages

This commit is contained in:
~lucidiot 2021-09-17 23:26:35 +02:00
parent fa6819e2fb
commit 04751e2755
5 changed files with 176 additions and 9 deletions

View File

@ -33,8 +33,8 @@ namespace SpectacleTransformer {
if (translation == null) {
MessageBox.Show(
"The API request was performed successfully, but the server did not return a valid translation payload. Response payload:\r\n" + responseBody,
"API error",
String.Format(Properties.Resources.InvalidPayloadError, responseBody),
Properties.Resources.InvalidPayloadErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
@ -44,33 +44,36 @@ namespace SpectacleTransformer {
}
string errorMessage = DecodeErrorResponse(responseBody);
string errorTitle;
if (String.IsNullOrEmpty(errorMessage)) {
errorMessage = String.Format(
"An unknown error occured while translating (HTTP {0} {1})",
Properties.Resources.UnknownTranslationError,
response.StatusCode,
response.StatusDescription
);
errorTitle = Properties.Resources.UnknownTranslationErrorTitle;
} else {
errorMessage = String.Format(
"An error occured while translating (HTTP {0} {1}):\r\n{2}",
Properties.Resources.TranslationError,
response.StatusCode,
response.StatusDescription,
errorMessage
);
errorTitle = Properties.Resources.TranslationErrorTitle;
}
MessageBox.Show(
errorMessage,
"API error",
errorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
return null;
} catch (WebException ex) {
MessageBox.Show(
"An error occured while running the API request:\r\n" + ex.ToString(),
"API error",
String.Format(Properties.Resources.HttpRequestError, ex.ToString()),
Properties.Resources.HttpRequestErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);

View File

@ -117,8 +117,8 @@ namespace SpectacleTransformer {
e.Result = ((TranslationRequest)e.Argument).Run();
} catch (Exception ex) {
MessageBox.Show(
"An unexpected error occurred when running the translation request: " + ex.ToString(),
"Error",
String.Format(Properties.Resources.GenericTranslationError, ex.ToString()),
Properties.Resources.GenericTranslationErrorTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Error
);

View File

@ -60,6 +60,62 @@ namespace SpectacleTransformer.Properties {
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à An unexpected error occurred when running the translation request: {0}.
/// </summary>
internal static string GenericTranslationError {
get {
return ResourceManager.GetString("GenericTranslationError", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Error.
/// </summary>
internal static string GenericTranslationErrorTitle {
get {
return ResourceManager.GetString("GenericTranslationErrorTitle", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à An error occured while running the API request:
///{0}.
/// </summary>
internal static string HttpRequestError {
get {
return ResourceManager.GetString("HttpRequestError", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à API error.
/// </summary>
internal static string HttpRequestErrorTitle {
get {
return ResourceManager.GetString("HttpRequestErrorTitle", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à The API request was performed successfully, but the server did not return a valid translation payload. Response payload:
///{0}.
/// </summary>
internal static string InvalidPayloadError {
get {
return ResourceManager.GetString("InvalidPayloadError", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Invalid translation payload.
/// </summary>
internal static string InvalidPayloadErrorTitle {
get {
return ResourceManager.GetString("InvalidPayloadErrorTitle", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Afrikaans.
/// </summary>
@ -1058,5 +1114,41 @@ namespace SpectacleTransformer.Properties {
return ResourceManager.GetString("LanguageCodes", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à An error occured while translating (HTTP {0} {1}):\r\n{2}.
/// </summary>
internal static string TranslationError {
get {
return ResourceManager.GetString("TranslationError", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Translation error.
/// </summary>
internal static string TranslationErrorTitle {
get {
return ResourceManager.GetString("TranslationErrorTitle", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à An unknown error occured while translating (HTTP {0} {1}).
/// </summary>
internal static string UnknownTranslationError {
get {
return ResourceManager.GetString("UnknownTranslationError", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Unknown error.
/// </summary>
internal static string UnknownTranslationErrorTitle {
get {
return ResourceManager.GetString("UnknownTranslationErrorTitle", resourceCulture);
}
}
}
}

View File

@ -447,4 +447,40 @@
<data name="lang_zu" xml:space="preserve">
<value>Zoulou</value>
</data>
<data name="GenericTranslationError" xml:space="preserve">
<value>Une erreur inattendue s'est produite en demandant une traduction : {0}</value>
<comment>{0} is an exception message and stack trace.</comment>
</data>
<data name="GenericTranslationErrorTitle" xml:space="preserve">
<value>Erreur</value>
</data>
<data name="HttpRequestError" xml:space="preserve">
<value>Une erreur s'est produite en exécutant une requête d'API :
{0}</value>
<comment>{0} is an exception message and stack trace.</comment>
</data>
<data name="HttpRequestErrorTitle" xml:space="preserve">
<value>Erreur d'API</value>
</data>
<data name="InvalidPayloadError" xml:space="preserve">
<value>La requête d'API s'est exécutée correctement, mais le serveur n'a pas renvoyé une traduction valide. Réponse reçue :
{0}</value>
</data>
<data name="InvalidPayloadErrorTitle" xml:space="preserve">
<value>Traduction invalide</value>
</data>
<data name="TranslationError" xml:space="preserve">
<value>Une erreur s'est produite durant la traduction (HTTP {0} {1}):\r\n{2}</value>
<comment>{0} is an HTTP status code. {1} is the name of that status code. {2} is the error message returned by the translation server.</comment>
</data>
<data name="TranslationErrorTitle" xml:space="preserve">
<value>Erreur de traduction</value>
</data>
<data name="UnknownTranslationError" xml:space="preserve">
<value>Une erreur inconnue s'est produite durant la traduction (HTTP {0} {1})</value>
<comment>{0} is an HTTP status code. {1} is the name of that status code.</comment>
</data>
<data name="UnknownTranslationErrorTitle" xml:space="preserve">
<value>Erreur inconnue</value>
</data>
</root>

View File

@ -451,4 +451,40 @@
<value>af,am,ar,az,be,bg,bn,bs,ca,ceb,co,cs,cy,da,de,el,en,eo,es,et,eu,fa,fi,fr,fy,ga,gd,gl,gu,ha,haw,hi,hmn,hr,ht,hu,hy,id,ig,is,it,iw,ja,jw,ka,kk,km,kn,ko,ku,ky,la,lb,lo,lt,lv,mg,mi,mk,ml,mn,mr,ms,mt,my,ne,nl,no,ny,or,pa,pl,ps,pt,ro,ru,rw,sd,si,sk,sl,sm,sn,so,sq,sr,st,su,sv,sw,ta,te,tg,th,tk,tl,tr,tt,ug,uk,ur,uz,vi,xh,yi,yo,zh,zh_HANT,zu</value>
<comment>Do not translate this.</comment>
</data>
<data name="GenericTranslationError" xml:space="preserve">
<value>An unexpected error occurred when running the translation request: {0}</value>
<comment>{0} is an exception message and stack trace.</comment>
</data>
<data name="GenericTranslationErrorTitle" xml:space="preserve">
<value>Error</value>
</data>
<data name="HttpRequestError" xml:space="preserve">
<value>An error occured while running the API request:
{0}</value>
<comment>{0} is an exception message and stack trace.</comment>
</data>
<data name="HttpRequestErrorTitle" xml:space="preserve">
<value>API error</value>
</data>
<data name="InvalidPayloadError" xml:space="preserve">
<value>The API request was performed successfully, but the server did not return a valid translation payload. Response payload:
{0}</value>
</data>
<data name="InvalidPayloadErrorTitle" xml:space="preserve">
<value>Invalid translation payload</value>
</data>
<data name="TranslationError" xml:space="preserve">
<value>An error occured while translating (HTTP {0} {1}):\r\n{2}</value>
<comment>{0} is an HTTP status code. {1} is the name of that status code. {2} is the error message returned by the translation server.</comment>
</data>
<data name="TranslationErrorTitle" xml:space="preserve">
<value>Translation error</value>
</data>
<data name="UnknownTranslationError" xml:space="preserve">
<value>An unknown error occured while translating (HTTP {0} {1})</value>
<comment>{0} is an HTTP status code. {1} is the name of that status code.</comment>
</data>
<data name="UnknownTranslationErrorTitle" xml:space="preserve">
<value>Unknown error</value>
</data>
</root>