Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/JA-126 Blazor component localization #125

Merged
merged 4 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions TutorLizard.Blazor/Components/AdSearchForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="form-check-input" />
</div>
<div class="form-group w-100 p-2 align-content-center">
<label class="control-label">Tytuł / Przedmiot / Opis:</label>
<label class="control-label">@Resources.AdSearchForm.Text</label>
<InputText @bind-Value="searchCriteria.Text"
class="form-control form-control-sm"
disabled="@(!searchCriteria.SearchByText)" />
Expand All @@ -21,7 +21,7 @@
class="form-check-input" />
</div>
<div class="form-group w-100 p-2 align-content-center">
<label class="control-label">Cena od:</label>
<label class="control-label">@Resources.AdSearchForm.PriceMin</label>
<InputNumber @bind-Value="searchCriteria.PriceMin"
class="form-control form-control-sm"
disabled="@(!searchCriteria.SearchByPriceMin)" />
Expand All @@ -32,7 +32,7 @@
class="form-check-input" />
</div>
<div class="form-group w-100 p-2 align-content-center">
<label class="control-label">Cena do:</label>
<label class="control-label">@Resources.AdSearchForm.PriceMax</label>
<InputNumber @bind-Value="searchCriteria.PriceMax"
class="form-control form-control-sm"
disabled="@(!searchCriteria.SearchByPriceMax)" />
Expand All @@ -44,7 +44,7 @@
class="form-check-input" />
</div>
<div class="form-group w-100 p-2 align-content-center">
<label class="control-label">Lokalizacja:</label>
<label class="control-label">@Resources.AdSearchForm.Location</label>
<InputText @bind-Value="searchCriteria.Location"
class="form-control form-control-sm"
disabled="@(!searchCriteria.SearchByLocation)" />
Expand All @@ -56,7 +56,7 @@
class="form-check-input" />
</div>
<div class="form-group w-100 p-2 align-content-center">
<label class="control-label">Kategoria:</label>
<label class="control-label">@Resources.AdSearchForm.Category</label>
<InputSelect @bind-Value="searchCriteria.CategoryId"
class="form-select"
disabled="@(!searchCriteria.SearchByCategoryId)">
Expand All @@ -75,7 +75,7 @@
<InputCheckbox @bind-Value="searchCriteria.IsRemote"
class="form-check-input"
disabled="@(!searchCriteria.SearchByIsRemote)" />
<label class="control-label">Nauczanie zdalne</label>
<label class="control-label">@Resources.AdSearchForm.IsRemote</label>
</div>
<input type="hidden" value="@searchOutputJson" name="searchCriteria" />
</div>
Expand Down
28 changes: 14 additions & 14 deletions TutorLizard.Blazor/Components/Calendar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
</div>
<div class="calendar-main">
<div class="seven-column-section days-header">
<div class="d-none d-xxl-block">Poniedziałek</div>
<div class="d-none d-xxl-block">Wtorek</div>
<div class="d-none d-xxl-block">Środa</div>
<div class="d-none d-xxl-block">Czwartek</div>
<div class="d-none d-xxl-block">Piątek</div>
<div class="d-none d-xxl-block">Sobota</div>
<div class="d-none d-xxl-block">Niedziela</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Monday</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Tuesday</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Wednesday</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Thursday</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Friday</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Saturday</div>
<div class="d-none d-xxl-block">@Resources.Schedule.Sunday</div>

<div class="d-xxl-none">Pn</div>
<div class="d-xxl-none">Wt</div>
<div class="d-xxl-none">Śr</div>
<div class="d-xxl-none">Czw</div>
<div class="d-xxl-none">Pt</div>
<div class="d-xxl-none">Sb</div>
<div class="d-xxl-none">Nd</div>
<div class="d-xxl-none">@Resources.Schedule.Monday_Abbr</div>
<div class="d-xxl-none">@Resources.Schedule.Tuesday_Abbr</div>
<div class="d-xxl-none">@Resources.Schedule.Wednesday_Abbr</div>
<div class="d-xxl-none">@Resources.Schedule.Thursday_Abbr</div>
<div class="d-xxl-none">@Resources.Schedule.Friday_Abbr</div>
<div class="d-xxl-none">@Resources.Schedule.Saturday_Abbr</div>
<div class="d-xxl-none">@Resources.Schedule.Sunday_Abbr</div>
</div>
<div class="seven-column-section calendar-grid">
<div class="@(DayOfWeekOnFirst()) @(IsSelected(1) ? "selected" : "")" @onclick="() => HandleDaySelected(1)">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="indicator-container">
@if (AsTutor > 0)
{
<span class="badge bg-success mx-md-1">N: @AsTutor</span>
<span class="badge bg-success mx-md-1">@Resources.Schedule.Indicator_Tutor: @AsTutor</span>
}
@if (AsStudent > 0)
{
<span class="badge bg-primary mx-md-1">U: @AsStudent</span>
<span class="badge bg-primary mx-md-1">@Resources.Schedule.Indicator_Student: @AsStudent</span>
}
</div>

Expand Down
14 changes: 12 additions & 2 deletions TutorLizard.Blazor/Components/Schedule.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using System.Text.Json
@using Microsoft.Extensions.Localization
@using TutorLizard.Shared.Models.DTOs

<div class="row">
Expand Down Expand Up @@ -27,27 +28,36 @@
[Parameter, EditorRequired]
public string? StudentsSchedule { get; set; }

string monday = "";

private List<IScheduleItemSummaryDto> schedule = [];
private List<IScheduleItemSummaryDto> scheduleForDay = [];

DateTime selectedDay = DateTime.Now;

protected override void OnParametersSet()
{
monday = Resources.Schedule.Monday;
schedule.Clear();
try
{
if (String.IsNullOrWhiteSpace(StudentsSchedule) == false)
{
var studentsSchedule = JsonSerializer
.Deserialize<IEnumerable<StudentsScheduleItemSummaryDto>>(StudentsSchedule);
schedule.AddRange(studentsSchedule);
if (studentsSchedule is not null)
{
schedule.AddRange(studentsSchedule);
}
}
if (String.IsNullOrWhiteSpace(TutorsSchedule) == false)
{
var tutorsSchedule = JsonSerializer
.Deserialize<IEnumerable<TutorsScheduleItemSummaryDto>>(TutorsSchedule);
schedule.AddRange(tutorsSchedule);
if (tutorsSchedule is not null)
{
schedule.AddRange(tutorsSchedule);
}
}
}
catch
Expand Down
4 changes: 2 additions & 2 deletions TutorLizard.Blazor/Components/ScheduleForDay.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@using TutorLizard.Shared.Models.DTOs
<div class="schedule-container my-2">
<h3>@($"{Day}.{Month}.{Year}")</h3>
<h3>@($"{Day.ToString("00")}.{Month.ToString("00")}.{Year}")</h3>
<div class="schedule-list">
@if (Schedule.Count == 0)
{
<div class="text-light text-center">Brak terminów.</div>
<div class="text-light text-center">@Resources.Schedule.ScheduleEmpty</div>
}
@foreach (var item in Schedule)
{
Expand Down
2 changes: 1 addition & 1 deletion TutorLizard.Blazor/Components/StudentsScheduleItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
<div class="item" @onclick="() => NavigateToAdDetails(ScheduleItem.AdId)">
<h4 class="display-6">@ScheduleItem.DateTime.ToString("HH:mm")</h4>
<div class="fw-bold">@ScheduleItem.AdTitle <small class="text-primary">| Jako uczeń</small></div>
<div class="fw-bold">@ScheduleItem.AdTitle <small class="text-primary">| @Resources.Schedule.AsStudent</small></div>
<div>Nauczyciel: @ScheduleItem.TutorName</div>
<div>Status zgłoszenia: @GetStatusName(ScheduleItem.Status)</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion TutorLizard.Blazor/Components/TutorsScheduleItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
<div class="item" @onclick="() => NavigateToAdDetails(ScheduleItem.AdId)">
<h4 class="display-6">@ScheduleItem.DateTime.ToString("HH:mm")</h4>
<div class="fw-bold">@ScheduleItem.AdTitle <small class="text-success">| Jako nauczyciel</small></div>
<div class="fw-bold">@ScheduleItem.AdTitle <small class="text-success">| @Resources.Schedule.AsTutor</small></div>
@if (ScheduleItem.AcceptedStudentsName is not null)
{
<div>Zaakceptowany uczeń: @ScheduleItem.AcceptedStudentsName</div>
Expand Down
30 changes: 29 additions & 1 deletion TutorLizard.Blazor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.JSInterop;
using System.Globalization;


const string defaultCulture = "en";

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});

builder.Services.Configure<RequestLocalizationOptions>(options =>
{
string[] supportedCultures = new[] { "pl", "en" };
options
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures)
.SetDefaultCulture("en");
});

var app = builder.Build();

var js = app.Services.GetRequiredService<IJSRuntime>();
var result = await js.InvokeAsync<string>("blazorCulture.get");
var culture = CultureInfo.GetCultureInfo(result ?? defaultCulture);

CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

await builder.Build().RunAsync();
await app.RunAsync();
117 changes: 117 additions & 0 deletions TutorLizard.Blazor/Resources/AdSearchForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading