Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'

- name: Restore
run: dotnet restore Localizer.slnx

- name: Build
run: dotnet build Localizer.slnx --no-restore --configuration Release

- name: Test
run: dotnet test Localizer.slnx --no-build --configuration Release --verbosity normal
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Timo Kuronen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
119 changes: 119 additions & 0 deletions Localizer.Desktop/ViewModels/MainViewModel.CatalogLifecycle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using CommunityToolkit.Mvvm.Input;

namespace Localizer.Desktop.ViewModels;

public partial class MainViewModel
{
[RelayCommand]
private async Task NewCatalogAsync()
{
var request = await _dialogs.PromptCreateCatalogAsync().ConfigureAwait(true);
if (request is null)
{
return;
}

var result = _createCatalog.Execute(request);
if (!result.Succeeded || result.Value is null)
{
await _dialogs.ShowMessageAsync("Create catalog failed", FormatError(result)).ConfigureAwait(true);
return;
}

SetCatalog(result.Value, path: null, dirty: true);
await LoadProjectFolderBindingAsync(result.Value.CatalogId.Value).ConfigureAwait(true);
StatusText = "Created new catalog.";
}

[RelayCommand]
private async Task OpenCatalogAsync(CancellationToken cancellationToken)
{
var path = await _dialogs.PickOpenCatalogPathAsync(cancellationToken).ConfigureAwait(true);
if (path is null)
{
return;
}

await RunIoAsync(async token =>
{
var result = await _openCatalog.ExecuteAsync(path, token).ConfigureAwait(true);
if (!result.Succeeded || result.Value is null)
{
await _dialogs.ShowMessageAsync("Open catalog failed", FormatError(result)).ConfigureAwait(true);
return;
}

SetCatalog(result.Value, path, dirty: false);
await LoadProjectFolderBindingAsync(result.Value.CatalogId.Value).ConfigureAwait(true);
StatusText = $"Opened {path}";
}, cancellationToken).ConfigureAwait(true);
}

[RelayCommand]
private async Task SaveCatalogAsync(CancellationToken cancellationToken)
{
if (_catalog is null)
{
return;
}

var path = _catalogPath;
if (string.IsNullOrWhiteSpace(path))
{
path = await _dialogs.PickSaveCatalogPathAsync(
suggestedFileName: $"{_catalog.CatalogId.Value}.json",
cancellationToken).ConfigureAwait(true);
if (path is null)
{
return;
}
}

await SaveToPathAsync(path, cancellationToken).ConfigureAwait(true);
}

[RelayCommand]
private async Task SaveCatalogAsAsync(CancellationToken cancellationToken)
{
if (_catalog is null)
{
return;
}

var path = await _dialogs.PickSaveCatalogPathAsync(
suggestedFileName: $"{_catalog.CatalogId.Value}.json",
cancellationToken).ConfigureAwait(true);
if (path is null)
{
return;
}

await SaveToPathAsync(path, cancellationToken).ConfigureAwait(true);
}

[RelayCommand]
private void CancelIo() => _ioCts?.Cancel();

private async Task SaveToPathAsync(string path, CancellationToken cancellationToken)
{
if (_catalog is null)
{
return;
}

await RunIoAsync(async token =>
{
var result = await _saveCatalog.ExecuteAsync(path, _catalog, token).ConfigureAwait(true);
if (!result.Succeeded)
{
await _dialogs.ShowMessageAsync("Save catalog failed", FormatError(result)).ConfigureAwait(true);
return;
}

_catalogPath = path;
IsDirty = false;
UpdateWindowTitle();
StatusText = $"Saved {path}";
}, cancellationToken).ConfigureAwait(true);
}
}
149 changes: 149 additions & 0 deletions Localizer.Desktop/ViewModels/MainViewModel.Drafting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using CommunityToolkit.Mvvm.Input;
using Localizer.Application.UseCases;

namespace Localizer.Desktop.ViewModels;

public partial class MainViewModel
{
[RelayCommand]
private async Task DraftMissingAndStaleAsync(CancellationToken cancellationToken) =>
await DraftAsync(
WorkQueueFilter.Missing | WorkQueueFilter.Stale,
"Requesting local model drafts for Missing and Stale items",
cancellationToken).ConfigureAwait(true);

[RelayCommand]
private async Task DraftAllAsync(CancellationToken cancellationToken) =>
await DraftAsync(
WorkQueueFilter.AllStatuses,
"Requesting local model drafts for all locales",
cancellationToken).ConfigureAwait(true);

private async Task DraftAsync(
WorkQueueFilter filter,
string busyStatus,
CancellationToken cancellationToken)
{
if (_catalog is null)
{
return;
}

var selectedKey = SelectedEntry?.Key;

BeginBusyStatus(busyStatus);
await RunIoAsync(async token =>
{
var result = await _requestTranslationDrafts
.ExecuteAsync(_catalog, new RequestTranslationDraftsRequest { Filter = filter }, token)
.ConfigureAwait(true);

if (!result.Succeeded)
{
await _dialogs.ShowMessageAsync("Draft failed", FormatError(result)).ConfigureAwait(true);
StatusText = "Drafting failed.";
return;
}

var outcome = result.Value!;
IsDirty = outcome.AppliedCount > 0 || IsDirty;
RefreshFromCatalog(selectKey: selectedKey);
RunValidation();

StatusText = outcome.RequestedCount == 0
? "No matching items to draft."
: $"Drafted {outcome.AppliedCount} of {outcome.RequestedCount} item(s).";

if (outcome.RejectionMessages.Count > 0)
{
var detail = string.Join(Environment.NewLine, outcome.RejectionMessages.Take(12));
if (outcome.RejectionMessages.Count > 12)
{
detail += $"{Environment.NewLine}...and {outcome.RejectionMessages.Count - 12} more.";
}

await _dialogs.ShowMessageAsync(
"Drafting finished with rejections",
detail).ConfigureAwait(true);
}
}, cancellationToken).ConfigureAwait(true);
}

private async Task ApproveTranslationRowAsync(TranslationEditViewModel row)
{
if (_catalog is null || string.IsNullOrWhiteSpace(EditorKey))
{
return;
}

var key = EditorKey;

if (row.HasTextChanged)
{
if (string.IsNullOrEmpty(row.Text))
{
await _dialogs.ShowMessageAsync(
"Approve failed",
"Translation text is empty. Enter text before approving.").ConfigureAwait(true);
return;
}

var draftResult = _setTranslationDraft.Execute(_catalog, new SetTranslationDraftRequest
{
Key = key,
Locale = row.Locale,
Text = row.Text
});

if (!draftResult.Succeeded)
{
await _dialogs.ShowMessageAsync("Approve failed", FormatError(draftResult)).ConfigureAwait(true);
return;
}
}

var approveResult = _approveTranslation.Execute(_catalog, new ApproveTranslationRequest
{
Key = key,
Locale = row.Locale
});

if (!approveResult.Succeeded)
{
await _dialogs.ShowMessageAsync("Approve failed", FormatError(approveResult)).ConfigureAwait(true);
RunValidation();
return;
}

IsDirty = true;
RefreshFromCatalog(selectKey: key);
RunValidation();
StatusText = $"Approved '{key}' for {row.Locale}.";
}

private async Task InvalidateTranslationRowAsync(TranslationEditViewModel row)
{
if (_catalog is null || string.IsNullOrWhiteSpace(EditorKey))
{
return;
}

var key = EditorKey;
var result = _invalidateTranslation.Execute(_catalog, new InvalidateTranslationRequest
{
Key = key,
Locale = row.Locale
});

if (!result.Succeeded)
{
await _dialogs.ShowMessageAsync("Invalidate failed", FormatError(result)).ConfigureAwait(true);
return;
}

IsDirty = true;
RefreshFromCatalog(selectKey: key);
RunValidation();
StatusText = $"Marked '{key}' ({row.Locale}) as Stale for re-draft.";
}
}
Loading
Loading