LANCommander/LANCommander.Launcher/UI/Depot/Components/DepotGameItem.razor
Pat Hartl 5a32bbf890 Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00

68 lines
2.2 KiB
Text

@using LANCommander.SDK.Models
@inject SDK.Client Client
@inject DepotService DepotService
@inject LibraryService LibraryService
@inject ImportService ImportService
@inject IMessageService MessageService
@inject ILogger<DepotGame> Logger
@inject LocalizationService LocalizationService
<div class="depot-game">
<div class="depot-game-cover" @onclick="() => OnClick.InvokeAsync(Item)">
@if (Item.DataItem is DepotGame game)
{
<SafeImage Media="game.Cover">
<div class="depot-game-default-cover">
<span>@Item.Name</span>
</div>
</SafeImage>
}
else
{
<div class="depot-game-default-cover">
<span>@Item.Name</span>
</div>
}
@if ((Item.DataItem is DepotGame game2 && !game2.InLibrary) || (Item != null && !LibraryService.IsInLibrary(Item!.Key)))
{
<Button class="depot-game-add-btn" Type="ButtonType.Primary" Icon="@IconType.Outline.Plus" Loading="Importing" OnClickStopPropagation="true" OnClick="AddToLibrary"/>
}
</div>
</div>
@code {
[Parameter] public Models.ListItem Item { get; set; }
[Parameter] public EventCallback<Models.ListItem> OnClick { get; set; }
bool Importing = false;
async Task AddToLibrary()
{
try
{
Importing = true;
StateHasChanged();
await Task.Yield();
await ImportService.ImportGameAsync(Item.Key);
await LibraryService.AddToLibraryAsync(Item.Key);
await LibraryService.RefreshItemsAsync();
Importing = false;
StateHasChanged();
await Task.Yield();
MessageService.Success(LocalizationService.GetString("GameAddedToLibrary", Item.Name));
}
catch (Exception ex)
{
Importing = false;
StateHasChanged();
await Task.Yield();
Logger?.LogError(ex, $"{Item.Name} ({Item.Key}) could not be added to your library!");
MessageService.Error(LocalizationService.GetString("GameCouldNotBeAddedToLibrary", Item.Name));
}
}
}