Skip to content

Commit

Permalink
Merge pull request #58 from RealAshampoo/develop
Browse files Browse the repository at this point in the history
Header information when Building a format
  • Loading branch information
tjorvenK authored Feb 15, 2023
2 parents 34813d8 + e46fe99 commit 9e41f7c
Show file tree
Hide file tree
Showing 29 changed files with 214 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ItemGroup>
<PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="MudBlazor" Version="6.1.2" />
<PackageReference Include="MudBlazor" Version="6.1.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Ashampoo.Translation.Systems.Formats.Abstractions\src\Ashampoo.Translation.Systems.Formats.Abstractions.csproj" />
Expand All @@ -38,7 +38,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageIcon>ash-logo-icon-big-128x.png</PackageIcon>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerIgnoreHeight>true</MinVerIgnoreHeight>
<MinVerDefaultPreReleasePhase>prerelease</MinVerDefaultPreReleasePhase>
<MinVerDefaultPreReleaseIdentifiers>prerelease.0</MinVerDefaultPreReleaseIdentifiers>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,14 +28,14 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.0.0" />
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static async Task<IFormat> BuildWithSourceAndTarget
AssignOptions options
)
{
if (!await ConfigureOptions(false, options)) throw new InvalidOperationException();
if (!await ConfigureOptions(true, options)) throw new InvalidOperationException();
var filter = options.Filter ?? new DefaultTranslationFilter();

var targetLanguage = options.TargetLanguage;
Expand All @@ -181,6 +181,7 @@ AssignOptions options

formatBuilder.SetTargetLanguage(targetLanguage);
formatBuilder.SetSourceLanguage(sourceLanguage);
formatBuilder.SetHeaderInformation(format.Header);

foreach (var unit in format)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,25 @@ public interface IFormatBuilder
/// The instance of <see cref="IFormat"/>.
/// </returns>
IFormat Build();


/// <summary>
/// Set the header information. All information will be added to the header and will overwrite
/// existing information. All previous information will be removed.
/// </summary>
/// <param name="header">
/// The <see cref="IFormatHeader"/> containing the information.
/// </param>
void SetHeaderInformation(IFormatHeader header);

/// <summary>
/// Add a header information. If the key already exists, the value will be overwritten.
/// </summary>
/// <param name="key">
/// The key of the information.
/// </param>
/// <param name="value">
/// The value of the information.
/// </param>
void AddHeaderInformation(string key, string value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class AshLangFormatBuilder : IFormatBuilderWithSourceAndTarget
private const string SourceLanguage = "en-US"; // AshLang source is always in English
private string? targetLanguage;
private readonly Dictionary<string, (string source, string target)> translations = new();
private Dictionary<string, string> information = new();

/// <inheritdoc />
public IFormat Build()
Expand All @@ -26,6 +27,14 @@ public IFormat Build()
TargetLanguage = targetLanguage
}
};

var appIdChunk = ashLang.Chunks.OfType<AppIdChunk>().FirstOrDefault();
if ( appIdChunk is not null && information.TryGetValue("Name", out var name))
{
appIdChunk.Name = name;
information.Remove("Name");
}

var translationChunk = (TranslationChunk)ashLang.Chunks.Last();

foreach (var (id, (source, target)) in translations)
Expand Down Expand Up @@ -62,4 +71,16 @@ public void SetTargetLanguage(string language)
{
targetLanguage = language;
}

/// <inheritdoc />
public void SetHeaderInformation(IFormatHeader header)
{
information = new Dictionary<string, string>(header);
}

/// <inheritdoc />
public void AddHeaderInformation(string key, string value)
{
information.Add(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void CopyTo(KeyValuePair<string, string>[] array, int arrayIndex)
/// <inheritdoc />
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
throw new NotImplementedException();
return XDataChunk.GetEnumerator();
}

/// <inheritdoc />
Expand All @@ -139,6 +139,6 @@ public bool TryGetValue(string key, [MaybeNullWhen(false)] out string value)

IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
return XDataChunk.GetEnumerator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageIcon>ash-logo-icon-big-128x.png</PackageIcon>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerIgnoreHeight>true</MinVerIgnoreHeight>
<MinVerDefaultPreReleasePhase>prerelease</MinVerDefaultPreReleasePhase>
<MinVerDefaultPreReleaseIdentifiers>prerelease.0</MinVerDefaultPreReleaseIdentifiers>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand All @@ -34,7 +34,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.6.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageIcon>ash-logo-icon-big-128x.png</PackageIcon>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerIgnoreHeight>true</MinVerIgnoreHeight>
<MinVerDefaultPreReleasePhase>prerelease</MinVerDefaultPreReleasePhase>
<MinVerDefaultPreReleaseIdentifiers>prerelease.0</MinVerDefaultPreReleaseIdentifiers>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand All @@ -28,7 +28,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Diagnostics" Version="7.1.2" />
<PackageReference Include="NPOI" Version="2.5.6" />
<PackageReference Include="NPOI" Version="2.6.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -39,7 +39,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ public IFormat Build()
foreach (var keyValuePair in translations)
{
var sourceTranslationString =
new DefaultTranslationString(keyValuePair.Key, keyValuePair.Value.Item1, sourceLanguage); //Create new translation string
new DefaultTranslationString(keyValuePair.Key, keyValuePair.Value.Item1,
sourceLanguage); //Create new translation string
var targetTranslationString =
new DefaultTranslationString(keyValuePair.Key, keyValuePair.Value.Item2, targetLanguage); //Create new translation string
new DefaultTranslationString(keyValuePair.Key, keyValuePair.Value.Item2,
targetLanguage); //Create new translation string

var translationUnit = new DefaultTranslationUnit(keyValuePair.Key) //Create new translation unit
{
Expand All @@ -67,4 +69,31 @@ public void SetTargetLanguage(string language)
{
targetLanguage = language;
}

/// <summary>
/// This method is not supported because <see cref="GengoFormat"/> does not support header information,
/// it will do nothing.
/// </summary>
/// <param name="header">
/// The <see cref="IFormatHeader"/> containing the information.
/// </param>
public void SetHeaderInformation(IFormatHeader header)
{
// Do nothing, Gengo does not support header information
}

/// <summary>
/// This method is not supported because <see cref="GengoFormat"/> does not support header information,
/// it will do nothing.
/// </summary>
/// <param name="key">
/// The key of the header information.
/// </param>
/// <param name="value">
/// The value of the header information.
/// </param>
public void AddHeaderInformation(string key, string value)
{
// Do nothing, Gengo does not support header information
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.6.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageIcon>ash-logo-icon-big-128x.png</PackageIcon>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerIgnoreHeight>true</MinVerIgnoreHeight>
<MinVerDefaultPreReleasePhase>prerelease</MinVerDefaultPreReleasePhase>
<MinVerDefaultPreReleaseIdentifiers>prerelease.0</MinVerDefaultPreReleaseIdentifiers>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand All @@ -34,7 +34,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ public IFormat Build()
return jsonFormat;
}

/// <summary>
/// This method does nothing, because JsonFormat does not support header information.
/// </summary>
/// <param name="header"></param>
public void SetHeaderInformation(IFormatHeader header)
{
// Do nothing, JsonFormat does not support header information
}

/// <summary>
/// This method does nothing, because JsonFormat does not support header information.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void AddHeaderInformation(string key, string value)
{
// Do nothing, JsonFormat does not support header information
}

/// <inheritdoc />
public void SetTargetLanguage(string language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.6.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageIcon>ash-logo-icon-big-128x.png</PackageIcon>
<MinVerTagPrefix>v</MinVerTagPrefix>
<MinVerIgnoreHeight>true</MinVerIgnoreHeight>
<MinVerDefaultPreReleasePhase>prerelease</MinVerDefaultPreReleasePhase>
<MinVerDefaultPreReleaseIdentifiers>prerelease.0</MinVerDefaultPreReleaseIdentifiers>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand All @@ -34,7 +34,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0">
<PackageReference Include="MinVer" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,23 @@ public void SetTargetLanguage(string language)
{
targetLanguage = language;
}

/// <summary>
/// This method does nothing, because NLangFormat does not support header information.
/// </summary>
/// <param name="header"></param>
public void SetHeaderInformation(IFormatHeader header)
{
// Do nothing, NLangFormat does not support header information
}

/// <summary>
/// This method does nothing, because NLangFormat does not support header information.
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void AddHeaderInformation(string key, string value)
{
// Do nothing, NLangFormat does not support header information
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.6.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading

0 comments on commit 9e41f7c

Please sign in to comment.