Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tjorvenK committed Sep 18, 2024
1 parent e163ddc commit 9a85568
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ void Read(Stream stream, FormatReadOptions? options = null) // TODO: require opt
/// </summary>
/// <param name="stream"></param>
/// <exception cref="UnsupportedFormatException"></exception>
void Write(Stream stream, FormatWriteOptions? options = null)
void Write(Stream stream)
{
WriteAsync(stream, options).Wait();
WriteAsync(stream).Wait();
}

/// <summary>
/// Writes the format to the given stream asynchronously.
/// </summary>
/// <param name="stream"></param>
/// <exception cref="UnsupportedFormatException"></exception>
Task WriteAsync(Stream stream, FormatWriteOptions? options = null);
Task WriteAsync(Stream stream);

/// <summary>
/// The <see cref="IFormatHeader"/> containing the header information for this format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public AshLangFormat()
}

/// <inheritdoc />
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
var chunkWriter = new ChunkWriter(stream, Chunks);
chunkWriter.Write();
}

/// <inheritdoc />
public Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
public Task WriteAsync(Stream stream)
{
Write(stream);
return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private Task<ITranslationUnit> ReadLine(CsvReader line)
}

/// <inheritdoc />
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,13 +35,14 @@ public static IServiceCollection RegisterFormats(this IServiceCollection service
services.AddSingleton<IFormatFactory, DefaultFormatFactory>();
services
.AddAshLangFormatFeatures()
.AddCsvFormat()
.AddGengoFormatFeatures()
.AddJavaPropertiesFormatFeatures()
.AddJsonFormatFeatures()
.AddNLangFormatFeatures()
.AddPOFormatFeatures()
.AddQtFormat()
.AddResXFormatFeatures()
.AddCsvFormat()
.AddTsProjFormatFeatures();

return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private string RemoveMarker(string str)
}

/// <inheritdoc />
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
Expand Down Expand Up @@ -206,9 +206,9 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
}

/// <inheritdoc />
public Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
public Task WriteAsync(Stream stream)
{
Write(stream, options);
Write(stream);
return Task.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private ITranslationUnit ParseLine(string? line, int lineNumber)
}

/// <inheritdoc/>
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
using StreamWriter writer = new(stream, leaveOpen: true);

Expand All @@ -120,7 +120,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
///
/// </summary>
/// <param name="stream"></param>
public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
public async Task WriteAsync(Stream stream)
{
await using StreamWriter writer = new(stream, leaveOpen: true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ private void ParseArray(string id, JsonElement element)
}

/// <inheritdoc />
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
WriteAsync(stream, options).Wait();
WriteAsync(stream).Wait();
}

/// <summary>
Expand All @@ -176,7 +176,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
/// <param name="stream">
/// The stream to write to.
/// </param>
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ private async Task<ITranslationUnit> ReadTranslation(LineReader lineReader)
}

/// <inheritdoc />
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
WriteAsync(stream, options).Wait();
WriteAsync(stream).Wait();
}

/// <summary>
Expand All @@ -132,7 +132,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
/// <exception cref="Exception">
/// Thrown if the format is invalid.
/// </exception>
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);
Expand Down
4 changes: 2 additions & 2 deletions src/Ashampoo.Translation.Systems.Formats/src/PO/POFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private async Task<IList<string>> ReadCommentsAsync(LineReader lineReader)
}

/// <inheritdoc />
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
using var writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true);

Expand Down Expand Up @@ -228,7 +228,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
/// <exception cref="Exception">
/// Thrown if an error occurs.
/// </exception>
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)..];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Ashampoo.Translation.Systems.Formats.PO;

/// <summary>
/// IFormatBuilderOptions for POFormat
/// </summary>
public sealed record PoBuilderOptions : IFormatBuilderOptions
{
/// <summary>
/// Disables splitting of the id into msgctxt and msgid if a pipe separator is detected.
/// </summary>
public bool PipeSplitting { get; init; } = true;
public bool SplitContextAndId { get; init; } = true;
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private List<string> GetComments(XElement element)
}

/// <inheritdoc />
public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
public async Task WriteAsync(Stream stream)
{
var test = XmlWriter.Create(stream, new XmlWriterSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void ReadTranslations()
}

/// <inheritdoc />
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
//Add an empty namespace and empty value
var ns = new XmlSerializerNamespaces();
Expand All @@ -146,7 +146,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
/// Asynchronously writes the current instance to the given <paramref name="stream"/>.
/// </summary>
/// <param name="stream"></param>
public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
public async Task WriteAsync(Stream stream)
{
var ns = new XmlSerializerNamespaces();
ns.Add("", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private async Task<bool> ConfigureHeader(FormatReadOptions? options)
}

/// <inheritdoc />
public void Write(Stream stream, FormatWriteOptions? options = null)
public void Write(Stream stream)
{
//Add an empty namespace and empty value
var ns = new XmlSerializerNamespaces();
Expand Down Expand Up @@ -200,7 +200,7 @@ public void Write(Stream stream, FormatWriteOptions? options = null)
/// <param name="stream">
/// The stream to write to.
/// </param>
public async Task WriteAsync(Stream stream, FormatWriteOptions? options = null)
public async Task WriteAsync(Stream stream)
{

//Add an empty namespace and empty value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 9a85568

Please sign in to comment.