From 9a8556813d053d0646a805f644fd62d568b3906a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tjorven=20K=C3=A4mpfer?=
<62958434+tjorvenK@users.noreply.github.com>
Date: Wed, 18 Sep 2024 10:50:25 +0200
Subject: [PATCH] cleanup
---
.../src/FormatWriteOptions.cs | 3 ---
.../src/IFormat.cs | 6 +++---
.../tests/FormatTest.cs | 2 +-
.../src/AshLang/AshLangFormat.cs | 4 ++--
.../src/CSV/CsvFormat.cs | 2 +-
.../src/DependencyInjection.cs | 4 +++-
.../src/Gengo/GengoFormat.cs | 6 +++---
.../src/JavaProperties/JavaPropertiesFormat.cs | 4 ++--
.../src/Json/JsonFormat.cs | 6 +++---
.../src/NLang/NLangFormat.cs | 6 +++---
src/Ashampoo.Translation.Systems.Formats/src/PO/POFormat.cs | 4 ++--
.../src/PO/POFormatBuilder.cs | 2 +-
.../src/PO/PoBuilderOptions.cs | 5 ++++-
src/Ashampoo.Translation.Systems.Formats/src/QT/QTFormat.cs | 2 +-
.../src/ResX/ResXFormat.cs | 4 ++--
.../src/TsProj/TsProjFormat.cs | 4 ++--
.../MockFormatWithTranslationUnits.cs | 2 +-
17 files changed, 34 insertions(+), 32 deletions(-)
delete mode 100644 src/Ashampoo.Translation.Systems.Formats.Abstractions/src/FormatWriteOptions.cs
diff --git a/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/FormatWriteOptions.cs b/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/FormatWriteOptions.cs
deleted file mode 100644
index ea1d5cc..0000000
--- a/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/FormatWriteOptions.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace Ashampoo.Translation.Systems.Formats.Abstractions;
-
-public record FormatWriteOptions;
\ No newline at end of file
diff --git a/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/IFormat.cs b/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/IFormat.cs
index e28e7e4..fcbcfc9 100644
--- a/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/IFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats.Abstractions/src/IFormat.cs
@@ -39,9 +39,9 @@ void Read(Stream stream, FormatReadOptions? options = null) // TODO: require opt
///
///
///
- void Write(Stream stream, FormatWriteOptions? options = null)
+ void Write(Stream stream)
{
- WriteAsync(stream, options).Wait();
+ WriteAsync(stream).Wait();
}
///
@@ -49,7 +49,7 @@ void Write(Stream stream, FormatWriteOptions? options = null)
///
///
///
- Task WriteAsync(Stream stream, FormatWriteOptions? options = null);
+ Task WriteAsync(Stream stream);
///
/// The containing the header information for this format.
diff --git a/src/Ashampoo.Translation.Systems.Formats.PO/tests/FormatTest.cs b/src/Ashampoo.Translation.Systems.Formats.PO/tests/FormatTest.cs
index 11445eb..cff14ea 100644
--- a/src/Ashampoo.Translation.Systems.Formats.PO/tests/FormatTest.cs
+++ b/src/Ashampoo.Translation.Systems.Formats.PO/tests/FormatTest.cs
@@ -59,7 +59,7 @@ public void CreateBuilderWithDisabledPipeSplittingTest()
}
}
poBuilder.SetTargetLanguage(format.Header.TargetLanguage);
- var newFormat = poBuilder.Build(new PoBuilderOptions { PipeSplitting = false });
+ var newFormat = poBuilder.Build(new PoBuilderOptions { SplitContextAndId = false });
var memoryStream = new MemoryStream();
newFormat.Write(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/AshLang/AshLangFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/AshLang/AshLangFormat.cs
index 53df20d..686fd12 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/AshLang/AshLangFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/AshLang/AshLangFormat.cs
@@ -47,14 +47,14 @@ public AshLangFormat()
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
var chunkWriter = new ChunkWriter(stream, Chunks);
chunkWriter.Write();
}
///
- public Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public Task WriteAsync(Stream stream)
{
Write(stream);
return Task.CompletedTask;
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs
index be2ddcf..01b4a45 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs
@@ -153,7 +153,7 @@ private Task ReadLine(CsvReader line)
}
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
Guard.IsNotNullOrWhiteSpace(Delimiter.ToString());
await using StreamWriter writer = new(stream, leaveOpen: true, encoding: Encoding.UTF8);
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/DependencyInjection.cs b/src/Ashampoo.Translation.Systems.Formats/src/DependencyInjection.cs
index 69e3556..6cc5ce9 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/DependencyInjection.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/DependencyInjection.cs
@@ -6,6 +6,7 @@
using Ashampoo.Translation.Systems.Formats.Json;
using Ashampoo.Translation.Systems.Formats.NLang;
using Ashampoo.Translation.Systems.Formats.PO;
+using Ashampoo.Translation.Systems.Formats.QT;
using Ashampoo.Translation.Systems.Formats.ResX;
using Ashampoo.Translation.Systems.Formats.TsProj;
using Microsoft.Extensions.DependencyInjection;
@@ -34,13 +35,14 @@ public static IServiceCollection RegisterFormats(this IServiceCollection service
services.AddSingleton();
services
.AddAshLangFormatFeatures()
+ .AddCsvFormat()
.AddGengoFormatFeatures()
.AddJavaPropertiesFormatFeatures()
.AddJsonFormatFeatures()
.AddNLangFormatFeatures()
.AddPOFormatFeatures()
+ .AddQtFormat()
.AddResXFormatFeatures()
- .AddCsvFormat()
.AddTsProjFormatFeatures();
return services;
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/Gengo/GengoFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/Gengo/GengoFormat.cs
index d22ce23..dcaae62 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/Gengo/GengoFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/Gengo/GengoFormat.cs
@@ -166,7 +166,7 @@ private string RemoveMarker(string str)
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
XSSFWorkbook workbook = new(); // Create a new workbook
var sheet = workbook.CreateSheet("Sheet 1"); // Create a new sheet
@@ -206,9 +206,9 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
}
///
- public Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public Task WriteAsync(Stream stream)
{
- Write(stream, options);
+ Write(stream);
return Task.CompletedTask;
}
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/JavaProperties/JavaPropertiesFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/JavaProperties/JavaPropertiesFormat.cs
index f099787..a3aa7bf 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/JavaProperties/JavaPropertiesFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/JavaProperties/JavaPropertiesFormat.cs
@@ -101,7 +101,7 @@ private ITranslationUnit ParseLine(string? line, int lineNumber)
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
using StreamWriter writer = new(stream, leaveOpen: true);
@@ -120,7 +120,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
///
///
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
await using StreamWriter writer = new(stream, leaveOpen: true);
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/Json/JsonFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/Json/JsonFormat.cs
index 984fcb0..9cd2743 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/Json/JsonFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/Json/JsonFormat.cs
@@ -165,9 +165,9 @@ private void ParseArray(string id, JsonElement element)
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
- WriteAsync(stream, options).Wait();
+ WriteAsync(stream).Wait();
}
///
@@ -176,7 +176,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
///
/// The stream to write to.
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
var root = new JsonObject();
CreateJsonObjects(root); // Create JSON objects from TranslationUnits
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/NLang/NLangFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/NLang/NLangFormat.cs
index a23d3e0..645a824 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/NLang/NLangFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/NLang/NLangFormat.cs
@@ -118,9 +118,9 @@ private async Task ReadTranslation(LineReader lineReader)
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
- WriteAsync(stream, options).Wait();
+ WriteAsync(stream).Wait();
}
///
@@ -132,7 +132,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
///
/// Thrown if the format is invalid.
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
// NLang is UTF16 LE
await using var writer = new StreamWriter(stream, Encoding.Unicode, leaveOpen: true);
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormat.cs
index 1d6f11c..2ee6d7c 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormat.cs
@@ -199,7 +199,7 @@ private async Task> ReadCommentsAsync(LineReader lineReader)
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
using var writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true);
@@ -228,7 +228,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
///
/// Thrown if an error occurs.
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
await using var writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true);
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormatBuilder.cs b/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormatBuilder.cs
index 9500610..b0f6d63 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormatBuilder.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/PO/POFormatBuilder.cs
@@ -37,7 +37,7 @@ public POFormat Build(IFormatBuilderOptions? options = null)
{
var translationUnit = new TranslationUnit(translation.Key);
var index = translation.Key.IndexOf(POConstants.Divider, StringComparison.InvariantCulture);
- if (builderOptions.PipeSplitting && index > 0) // if divider exists, then a message context is used
+ if (builderOptions.SplitContextAndId && index > 0) // if divider exists, then a message context is used
{
var ctxt = translation.Key[..index];
var msgId = translation.Key[(index + POConstants.Divider.Length)..];
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/PO/PoBuilderOptions.cs b/src/Ashampoo.Translation.Systems.Formats/src/PO/PoBuilderOptions.cs
index f38513a..f75a2c1 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/PO/PoBuilderOptions.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/PO/PoBuilderOptions.cs
@@ -2,10 +2,13 @@
namespace Ashampoo.Translation.Systems.Formats.PO;
+///
+/// IFormatBuilderOptions for POFormat
+///
public sealed record PoBuilderOptions : IFormatBuilderOptions
{
///
/// Disables splitting of the id into msgctxt and msgid if a pipe separator is detected.
///
- public bool PipeSplitting { get; init; } = true;
+ public bool SplitContextAndId { get; init; } = true;
};
\ No newline at end of file
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/QT/QTFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/QT/QTFormat.cs
index 549e9a1..7519586 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/QT/QTFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/QT/QTFormat.cs
@@ -83,7 +83,7 @@ private List GetComments(XElement element)
}
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
var test = XmlWriter.Create(stream, new XmlWriterSettings
{
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/ResX/ResXFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/ResX/ResXFormat.cs
index 27ffe60..9a544c3 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/ResX/ResXFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/ResX/ResXFormat.cs
@@ -122,7 +122,7 @@ private void ReadTranslations()
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
//Add an empty namespace and empty value
var ns = new XmlSerializerNamespaces();
@@ -146,7 +146,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
/// Asynchronously writes the current instance to the given .
///
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
var ns = new XmlSerializerNamespaces();
ns.Add("", "");
diff --git a/src/Ashampoo.Translation.Systems.Formats/src/TsProj/TsProjFormat.cs b/src/Ashampoo.Translation.Systems.Formats/src/TsProj/TsProjFormat.cs
index 8ec9a28..42ca342 100644
--- a/src/Ashampoo.Translation.Systems.Formats/src/TsProj/TsProjFormat.cs
+++ b/src/Ashampoo.Translation.Systems.Formats/src/TsProj/TsProjFormat.cs
@@ -172,7 +172,7 @@ private async Task ConfigureHeader(FormatReadOptions? options)
}
///
- public void Write(Stream stream, FormatWriteOptions? options = null)
+ public void Write(Stream stream)
{
//Add an empty namespace and empty value
var ns = new XmlSerializerNamespaces();
@@ -200,7 +200,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
///
/// The stream to write to.
///
- public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public async Task WriteAsync(Stream stream)
{
//Add an empty namespace and empty value
diff --git a/src/tests/Ashampoo.Translation.Systems.TestBase/MockFormatWithTranslationUnits.cs b/src/tests/Ashampoo.Translation.Systems.TestBase/MockFormatWithTranslationUnits.cs
index d8bde3b..b2a8378 100644
--- a/src/tests/Ashampoo.Translation.Systems.TestBase/MockFormatWithTranslationUnits.cs
+++ b/src/tests/Ashampoo.Translation.Systems.TestBase/MockFormatWithTranslationUnits.cs
@@ -28,7 +28,7 @@ private MockFormatWithTranslationUnits(Language language, string id, string valu
TranslationUnits.Add(translationUnit);
}
- public Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
+ public Task WriteAsync(Stream stream)
{
throw new NotImplementedException();
}