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

release #89

Merged
merged 1 commit into from
Sep 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@ public record FormatStringOption(string Name, bool Required = false) : FormatOpt
public string Value { get; set; } = "";
}

/// <summary>
/// Format option for a char value.
/// </summary>
/// <param name="Name">
/// <inheritdoc cref="FormatOption"/>
/// </param>
/// <param name="Required">
/// <inheritdoc cref="FormatOption"/>
/// </param>
public record FormatCharacterOption(string Name, bool Required = false) : FormatOption(Name, Required)
{
/// <summary>
/// The value of the option.
/// </summary>
public string Value { get; set; } = ";";
}

/// <summary>
/// Configuration object for a <see cref="IFormat"/> containing a list of <see cref="FormatOption">FormatOptions</see>.
/// </summary>
Expand Down
50 changes: 31 additions & 19 deletions src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

private const char CommentDelimiter = '|';

public CsvFormat()

Check warning on line 34 in src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'CsvFormat.CsvFormat()'

Check warning on line 34 in src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'CsvFormat.CsvFormat()'

Check warning on line 34 in src/Ashampoo.Translation.Systems.Formats/src/CSV/CsvFormat.cs

View workflow job for this annotation

GitHub Actions / publish-formats-package / publish-nuget-package

Missing XML comment for publicly visible type or member 'CsvFormat.CsvFormat()'
{
var csvFormatHeader = new CsvFormatHeader();
Header = csvFormatHeader;
Expand Down Expand Up @@ -81,32 +81,44 @@
switch (headerLine[0].Trim())
{
case "#Delimiter":
if (char.IsWhiteSpace(Delimiter) && !string.IsNullOrWhiteSpace(headerLine[1]))
{
CsvFormatHeader.Delimiter = headerLine[1].Trim().ToCharArray().First();
}

TryApplyDelimiter(headerLine);
break;
case "#Source Language":
if (string.IsNullOrWhiteSpace(options.SourceLanguage?.Value) &&
!string.IsNullOrWhiteSpace(headerLine[1]))
{
Header.SourceLanguage = new Language(headerLine[1].Trim());
}

TryApplySourceLanguage(options, headerLine);
break;
case "#Target Language":
if (string.IsNullOrWhiteSpace(options.TargetLanguage.Value) &&
!string.IsNullOrWhiteSpace(headerLine[1]))
{
Header.TargetLanguage = new Language(headerLine[1].Trim());
}

TryApplyTargetLanguage(options, headerLine);
break;
}
}
}

private void TryApplyTargetLanguage(FormatReadOptions options, string[] headerLine)
{
if (string.IsNullOrWhiteSpace(options.TargetLanguage.Value) &&
!string.IsNullOrWhiteSpace(headerLine[1]))
{
Header.TargetLanguage = new Language(headerLine[1].Trim());
}
}

private void TryApplySourceLanguage(FormatReadOptions options, string[] headerLine)
{
if (string.IsNullOrWhiteSpace(options.SourceLanguage?.Value) &&
!string.IsNullOrWhiteSpace(headerLine[1]))
{
Header.SourceLanguage = new Language(headerLine[1].Trim());
}
}

private void TryApplyDelimiter(string[] headerLine)
{
if (char.IsWhiteSpace(Delimiter) && !string.IsNullOrWhiteSpace(headerLine[1]))
{
CsvFormatHeader.Delimiter = headerLine[1].Trim()[0];
}
}

private async Task ReadCsv(CsvReader reader)
{
await reader.ReadAsync();
Expand Down Expand Up @@ -200,7 +212,7 @@

FormatStringOption targetLanguageOption = new("Target language", true);
FormatStringOption sourceLanguageOption = new("Source language", true);
FormatCharacterOption delimiterOption = new("Delimiter", true);
FormatStringOption delimiterOption = new("Delimiter", true);

List<FormatOption> optionList = [];
if (setTargetLanguage) optionList.Add(targetLanguageOption);
Expand Down Expand Up @@ -237,7 +249,7 @@
}
}

file record CsvRecordFormat
file sealed record CsvRecordFormat
{
[Name("id")] public string Id { get; init; } = string.Empty;

Expand Down
Loading