Skip to content

Commit

Permalink
localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Jebzou committed Nov 24, 2024
1 parent 80bc5e1 commit 2e5fb1d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
10 changes: 6 additions & 4 deletions ElectronicObserver/Data/Bonodere/BonodereHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

namespace ElectronicObserver.Data.Bonodere;

public class BonodereHttpClient
public class BonodereHttpClient(BonodereSubmissionTranslationViewModel translations)
{
private HttpClient? CurrentClient { get; set; }

public bool IsReady => CurrentClient is not null;

private BonodereSubmissionTranslationViewModel Translations { get; } = translations;

private static HttpClient MakeHttpClient() => new()
{
BaseAddress = new("https://bonodere.famluro.es/api/"),
Expand Down Expand Up @@ -119,7 +121,7 @@ public async Task SubmitData(List<SenkaEntryModel> data)
}
else
{
Logger.Add(2, "Bonodere submission : Success");
Logger.Add(2, Translations.Success);
}
}

Expand All @@ -131,8 +133,8 @@ private async Task HandleErrorResponse(HttpResponseMessage response)
{
Logger.Add(2, errorData switch
{
{ Code: >0 } => $"Bonodere error : {errorData.Message} ({errorData.Code})",
_ => $"Bonodere error : {errorData.Message}",
{ Code: >0 } => $"{BonodereSubmissionResources.BonodereError} : {errorData.Message} ({errorData.Code})",
_ => $"{BonodereSubmissionResources.BonodereError} {errorData.Message}",
});
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BonodereError" xml:space="preserve">
<value>Bonodere error</value>
</data>
<data name="BonodereSubmissionSuccess" xml:space="preserve">
<value>Bonodere submission : Success</value>
</data>
<data name="InconsistantDataDetected" xml:space="preserve">
<value>Inconsistant data detected</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BonodereError" xml:space="preserve">
<value>Bonodere エラー</value>
</data>
<data name="BonodereSubmissionSuccess" xml:space="preserve">
<value>??? (Bonodere submission : Success)</value>
</data>
<data name="InconsistantDataDetected" xml:space="preserve">
<value>??? (Inconsistant data detected)</value>
</data>
Expand Down
9 changes: 5 additions & 4 deletions ElectronicObserver/Data/Bonodere/BonodereSubmissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ public class BonodereSubmissionService
{
private BonodereSubmissionTranslationViewModel BonodereSubmission { get; }

private BonodereHttpClient BonodereClient { get; } = new();
private BonodereHttpClient BonodereClient { get; }

public string Username { get; set; } = "";

public BonodereSubmissionService(BonodereSubmissionTranslationViewModel translations)
{
BonodereSubmission = translations;
BonodereClient = new(BonodereSubmission);

_ = LoginFromSavedToken();

Expand Down Expand Up @@ -71,7 +72,7 @@ public async Task SubmitData(List<SenkaEntryModel> data)

if (!IsDataValid(data))
{
Logger.Add(2, $"Bonodere error: {BonodereSubmission.InconsistantDataDetected}");
Logger.Add(2, $"{BonodereSubmission.Error}: {BonodereSubmission.InconsistantDataDetected}");
return;
}

Expand All @@ -95,8 +96,8 @@ private bool IsDataValid(List<SenkaEntryModel> data)
return true;
}

private static void LogError(Exception e)
private void LogError(Exception e)
{
Logger.Add(2, "Bonodere error", e);
Logger.Add(2, BonodereSubmission.Error, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ namespace ElectronicObserver.Data.Bonodere;
public class BonodereSubmissionTranslationViewModel : TranslationBaseViewModel
{
public string InconsistantDataDetected => BonodereSubmissionResources.InconsistantDataDetected;
public string Error => BonodereSubmissionResources.BonodereError;
public string Success => BonodereSubmissionResources.BonodereSubmissionSuccess;
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private async Task BonodereLogin(SecureString password)
{
LoginError = ex.Message;

Logger.Add(2, "Bonodere error", ex);
Logger.Add(2, BonodereSubmissionResources.BonodereError, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void HandleData(string apiname, dynamic data)
}
catch (Exception ex)
{
Logger.Add(2, "Bonodere error", ex);
Logger.Add(2, BonodereSubmissionResources.BonodereError, ex);
}
finally
{
Expand Down

0 comments on commit 2e5fb1d

Please sign in to comment.