-
Notifications
You must be signed in to change notification settings - Fork 2
Localisation Layer #603
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
Open
gruenwaldlk
wants to merge
5
commits into
master
Choose a base branch
from
features/gruenwaldlk/localisation_layer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Localisation Layer #603
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ddbb2e2
Localisation Layer
gruenwaldlk c89dd01
Merge branch 'master' into features/gruenwaldlk/localisation_layer
gruenwaldlk a47ca38
Language Support with Game Distinction
gruenwaldlk ac73a5c
Address Review
gruenwaldlk a779d37
Fix CreditsTextfile Import
gruenwaldlk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| // Copyright (c) Alamo Engine Tools and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for details. | ||
|
|
||
| using AnakinRaW.CommonUtilities.Hashing; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
| using PG.Commons; | ||
| using PG.StarWarsGame.Files.DAT.Binary; | ||
| using PG.StarWarsGame.Files.DAT.Services; | ||
|
|
||
| namespace PG.StarWarsGame.Files.DAT; | ||
|
|
||
| /// <summary> | ||
|
|
@@ -18,10 +22,13 @@ public static class DatServiceContribution | |
| /// <param name="serviceCollection">The <see cref="IServiceCollection"/> to add services to.</param> | ||
| public static void SupportDAT(this IServiceCollection serviceCollection) | ||
| { | ||
| PetroglyphCommons.ContributeServices(serviceCollection); | ||
| serviceCollection.TryAddSingleton<IHashingService>(sp => new HashingService(sp)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. providing the hashing service, for me, is also responsibility of the consumer |
||
|
|
||
| serviceCollection | ||
| .AddSingleton<IDatFileService>(sp => new DatFileService(sp)) | ||
| .AddSingleton<IDatModelService>(sp => new DatModelService(sp)) | ||
| .AddTransient<IDatFileReader>(sp => new DatFileReader(sp)) | ||
| .AddTransient<IDatBinaryConverter>(sp => new DatBinaryConverter(sp)); | ||
| } | ||
| } | ||
| } | ||
140 changes: 140 additions & 0 deletions
140
...on.Baseline/PG.StarWarsGame.Localisation.Baseline.Test/BaselineTranslationProviderTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // Copyright (c) Alamo Engine Tools and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for details. | ||
|
|
||
| using System; | ||
| using System.Linq; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using PG.StarWarsGame.Localisation.Languages; | ||
| using PG.Testing; | ||
| using Xunit; | ||
|
|
||
| namespace PG.StarWarsGame.Localisation.Baseline.Test; | ||
|
|
||
| public class BaselineTranslationProviderTest : PGTestBase | ||
| { | ||
| protected override void SetupServices(IServiceCollection serviceCollection) | ||
| { | ||
| base.SetupServices(serviceCollection); | ||
| serviceCollection.SupportLocalisationBaseline(); | ||
| } | ||
|
|
||
| private IBaselineTranslationProvider Provider => | ||
| ServiceProvider.GetRequiredService<IBaselineTranslationProvider>(); | ||
|
|
||
| [Theory] | ||
| [InlineData(GameContext.EaW)] | ||
| [InlineData(GameContext.FoC)] | ||
| public void GetMasterText_SingleLanguage_IsNonEmpty(GameContext game) | ||
| { | ||
| var lang = new EnglishAlamoLanguageDefinition(); | ||
| var db = Provider.GetMasterText(game, lang); | ||
| Assert.NotEmpty(db); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(GameContext.EaW)] | ||
| [InlineData(GameContext.FoC)] | ||
| public void GetCreditsText_SingleLanguage_IsNonEmpty(GameContext game) | ||
| { | ||
| var lang = new EnglishAlamoLanguageDefinition(); | ||
| var db = Provider.GetCreditsText(game, lang); | ||
| Assert.NotEmpty(db); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetMasterText_MultiLanguage_ContainsAllRequestedLanguages() | ||
| { | ||
| var langs = new IAlamoLanguageDefinition[] | ||
| { | ||
| new EnglishAlamoLanguageDefinition(), | ||
| new GermanAlamoLanguageDefinition(), | ||
| }; | ||
| var db = Provider.GetMasterText(GameContext.EaW, langs); | ||
| Assert.Equal(2, db.Languages.Count); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetMasterText_EaW_English_ContainsKnownKey() | ||
| { | ||
| var lang = new EnglishAlamoLanguageDefinition(); | ||
| var db = Provider.GetMasterText(GameContext.EaW, lang); | ||
| Assert.True(db.Count > 100); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(GameContext.EaW)] | ||
| [InlineData(GameContext.FoC)] | ||
| public void GetCreditsText_MultiLanguage_MergesLanguagesIntoSharedRows(GameContext game) | ||
| { | ||
| var en = new EnglishAlamoLanguageDefinition(); | ||
| var de = new GermanAlamoLanguageDefinition(); | ||
|
|
||
| var single = Provider.GetCreditsText(game, en); | ||
| var multi = Provider.GetCreditsText(game, new IAlamoLanguageDefinition[] { en, de }); | ||
|
|
||
| // Adding a language must not multiply the row count. | ||
| Assert.Equal(single.Count, multi.Count); | ||
| Assert.Contains(multi, e => e.TryGetTranslation(en, out _) && e.TryGetTranslation(de, out _)); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(GameContext.EaW)] | ||
| [InlineData(GameContext.FoC)] | ||
| public void GetCreditsText_MultiLanguage_RowsAlignWithSingleLanguageLoad(GameContext game) | ||
| { | ||
| var en = new EnglishAlamoLanguageDefinition(); | ||
| var de = new GermanAlamoLanguageDefinition(); | ||
|
|
||
| var single = Provider.GetCreditsText(game, en); | ||
| var multi = Provider.GetCreditsText(game, new IAlamoLanguageDefinition[] { en, de }); | ||
|
|
||
| Assert.Equal(single.Count, multi.Count); | ||
|
|
||
| // Every row must sit at the same index and carry the same English text as the single-language load; | ||
| // a merge that slipped by one row would still have the right count but the wrong pairings. | ||
| for (var i = 0; i < single.Count; i++) | ||
| { | ||
| Assert.Equal(single[i].Key, multi[i].Key); | ||
| single[i].TryGetTranslation(en, out var expected); | ||
| multi[i].TryGetTranslation(en, out var actual); | ||
| Assert.Equal(expected, actual); | ||
| } | ||
|
|
||
| Assert.All(multi, e => Assert.True(e.TryGetTranslation(de, out _))); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetMasterText_MultiLanguage_MergesLanguagesOntoSharedKeys() | ||
| { | ||
| var en = new EnglishAlamoLanguageDefinition(); | ||
| var de = new GermanAlamoLanguageDefinition(); | ||
|
|
||
| var single = Provider.GetMasterText(GameContext.EaW, en); | ||
| var multi = Provider.GetMasterText(GameContext.EaW, new IAlamoLanguageDefinition[] { en, de }); | ||
|
|
||
| // Keyed storage merges by key, so adding a language must widen entries, never stack copies. | ||
| Assert.True(multi.Count < single.Count * 2); | ||
| Assert.Contains(multi, e => e.TryGetTranslation(en, out _) && e.TryGetTranslation(de, out _)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetCreditsText_LanguageMappedWithoutResource_LeavesLoadedRowsIntact() | ||
| { | ||
| var en = new EnglishAlamoLanguageDefinition(); | ||
| var ru = new RussianAlamoLanguageDefinition(); | ||
|
|
||
| var single = Provider.GetCreditsText(GameContext.EaW, en); | ||
| var multi = Provider.GetCreditsText(GameContext.EaW, new IAlamoLanguageDefinition[] { en, ru }); | ||
|
|
||
| // Russian is mapped in LanguageMap but ships no .dat resource; it must be a silent no-op | ||
| // rather than appending empty rows onto the English ones. | ||
| Assert.Equal(single.Count, multi.Count); | ||
| Assert.DoesNotContain(multi, e => e.TryGetTranslation(ru, out _)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetMasterText_NullLanguage_Throws() | ||
| { | ||
| Assert.Throws<ArgumentNullException>(() => Provider.GetMasterText(GameContext.EaW, (IAlamoLanguageDefinition)null!)); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
...StarWarsGame.Localisation.Baseline.Test/PG.StarWarsGame.Localisation.Baseline.Test.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>net8.0;net10.0</TargetFrameworks> | ||
| <TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net481</TargetFrameworks> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <IsPackable>false</IsPackable> | ||
| <IsTestable>true</IsTestable> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="GitHubActionsTestLogger" Version="3.0.4" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" /> | ||
| <PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" /> | ||
| <PackageReference Include="Microsoft.Testing.Platform" Version="2.2.3" /> | ||
| <PackageReference Include="coverlet.msbuild" Version="10.0.1"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="coverlet.collector" Version="10.0.1"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\PG.Testing\PG.Testing.csproj" /> | ||
| <ProjectReference Include="..\..\PG.StarWarsGame.Files.DAT\PG.StarWarsGame.Files.DAT\PG.StarWarsGame.Files.DAT.csproj" /> | ||
| <ProjectReference Include="..\PG.StarWarsGame.Localisation.Baseline\PG.StarWarsGame.Localisation.Baseline.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
28 changes: 28 additions & 0 deletions
28
...ocalisation.Baseline/PG.StarWarsGame.Localisation.Baseline/BaselineServiceContribution.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) Alamo Engine Tools and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for details. | ||
|
|
||
| using Microsoft.Extensions.DependencyInjection; | ||
| using PG.StarWarsGame.Files.DAT; | ||
|
|
||
| namespace PG.StarWarsGame.Localisation.Baseline | ||
| { | ||
| /// <summary> | ||
| /// Provides initialization routines for the PG.StarWarsGame.Localisation.Baseline library. | ||
| /// </summary> | ||
| public static class BaselineServiceContribution | ||
| { | ||
| /// <summary> | ||
| /// Adds all services required by this library, including DAT and localisation core services. | ||
| /// </summary> | ||
| public static IServiceCollection SupportLocalisationBaseline(this IServiceCollection serviceCollection) | ||
| { | ||
| serviceCollection.SupportDAT(); | ||
| serviceCollection.SupportLocalisation(); | ||
|
|
||
| serviceCollection.AddSingleton<IBaselineTranslationProvider>(sp => | ||
| new BaselineTranslationProvider(sp)); | ||
|
|
||
| return serviceCollection; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
providing the hashing service, for me, is also responsibility of the consumer