Skip to content

Commit c02481e

Browse files
committed
Base Setup
1 parent deacfce commit c02481e

20 files changed

+593
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using PG.StarWarsGame.Components.Localisation.Languages.BuiltIn;
7+
8+
namespace PG.StarWarsGame.Components.Localisation.Test;
9+
10+
public sealed class LocalisationTestConstants
11+
{
12+
public static readonly IList<Type> REGISTERED_LANGUAGE_DEFINITIONS = new List<Type>
13+
{
14+
//[gruenwaldlu, 2021-04-18-12:02:51+2]: All officially supported languages are listed below.
15+
typeof(ChineseAlamoLanguageDefinition), typeof(EnglishAlamoLanguageDefinition),
16+
typeof(FrenchAlamoLanguageDefinition), typeof(GermanAlamoLanguageDefinition),
17+
typeof(ItalianAlamoLanguageDefinition), typeof(JapaneseAlamoLanguageDefinition),
18+
typeof(KoreanAlamoLanguageDefinition), typeof(PolishAlamoLanguageDefinition),
19+
typeof(RussianAlamoLanguageDefinition), typeof(SpanishAlamoLanguageDefinition),
20+
typeof(ThaiAlamoLanguageDefinition)
21+
};
22+
23+
public static readonly Type DEFAULT_LANGUAGE = typeof(EnglishAlamoLanguageDefinition);
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<IsPackable>false</IsPackable>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
5+
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net48</TargetFrameworks>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
9+
<PrivateAssets>all</PrivateAssets>
10+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
11+
</PackageReference>
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
15+
<PackageReference Include="xunit" Version="2.8.1" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.2">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
<PackageReference Include="System.IO.Abstractions" Version="21.0.2" />
25+
<PackageReference Include="Testably.Abstractions.Testing" Version="3.2.1" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<ProjectReference Include="..\..\PG.Commons\PG.Commons.Test\PG.Commons.Test.csproj" />
29+
<ProjectReference Include="..\..\PG.Testing\PG.Testing.csproj" />
30+
<ProjectReference Include="..\PG.StarWarsGame.Components.Localisation\PG.StarWarsGame.Components.Localisation.csproj" />
31+
</ItemGroup>
32+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System;
5+
6+
namespace PG.StarWarsGame.Components.Localisation.Attributes;
7+
8+
/// <summary>
9+
/// Marks the default (fallback) language.
10+
/// </summary>
11+
public class DefaultLanguageAttribute : Attribute
12+
{
13+
/// <summary>
14+
/// .ctor
15+
/// </summary>
16+
public DefaultLanguageAttribute()
17+
{
18+
IsDefaultLanguage = true;
19+
}
20+
21+
/// <summary>
22+
/// .ctor
23+
/// </summary>
24+
/// <param name="isDefaultLanguage"></param>
25+
public DefaultLanguageAttribute(bool isDefaultLanguage)
26+
{
27+
IsDefaultLanguage = isDefaultLanguage;
28+
}
29+
30+
/// <summary>
31+
/// Returns true for the default language.
32+
/// </summary>
33+
public bool IsDefaultLanguage { get; }
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System;
5+
using System.Diagnostics.CodeAnalysis;
6+
7+
namespace PG.StarWarsGame.Components.Localisation.Attributes;
8+
9+
/// <summary>
10+
/// Marks a language as officially supported.
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
13+
[ExcludeFromCodeCoverage]
14+
public sealed class OfficiallySupportedLanguageAttribute : Attribute
15+
{
16+
/// <summary>
17+
/// .ctor
18+
/// </summary>
19+
public OfficiallySupportedLanguageAttribute()
20+
{
21+
IsOfficiallySupported = true;
22+
}
23+
24+
/// <summary>
25+
/// .ctor
26+
/// </summary>
27+
/// <param name="isOfficiallySupported"></param>
28+
public OfficiallySupportedLanguageAttribute(bool isOfficiallySupported)
29+
{
30+
IsOfficiallySupported = isOfficiallySupported;
31+
}
32+
33+
/// <summary>
34+
/// Returns true if the language is officially supported.
35+
/// </summary>
36+
public bool IsOfficiallySupported { get; }
37+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System;
5+
using System.Globalization;
6+
7+
namespace PG.StarWarsGame.Components.Localisation.Languages;
8+
9+
/// <summary>
10+
/// Abstract language definition
11+
/// </summary>
12+
public abstract class AlamoLanguageDefinitionBase : IAlamoLanguageDefinition, IComparable
13+
{
14+
/// <summary>
15+
/// A string that is being used to identify the language of the *.DAT file, e.g. a language identifier
16+
/// "english" would produce the file "mastertextfile_english.dat"
17+
/// </summary>
18+
protected abstract string ConfiguredLanguageIdentifier { get; }
19+
20+
/// <summary>
21+
/// The .NET Culture that best describes the language. This culture can be used for spell checking,
22+
/// auto-translation between languages, etc.
23+
/// </summary>
24+
protected abstract CultureInfo ConfiguredCulture { get; }
25+
26+
/// <inheritdoc />
27+
public string LanguageIdentifier => ConfiguredLanguageIdentifier;
28+
29+
/// <inheritdoc />
30+
public CultureInfo Culture => ConfiguredCulture;
31+
32+
/// <inheritdoc />
33+
public int CompareTo(object obj)
34+
{
35+
if (obj is not IAlamoLanguageDefinition other)
36+
throw new ArgumentException(
37+
$"The type of {obj.GetType()} is not assignable to {typeof(IAlamoLanguageDefinition)}. The two objects cannot be compared.");
38+
39+
return CompareToInternal(other);
40+
}
41+
42+
/// <summary>
43+
/// Compares the current instance with another object of the same type and returns an integer that indicates
44+
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
45+
/// other object.
46+
/// </summary>
47+
/// <remarks>
48+
/// The <see cref="IAlamoLanguageDefinition" /> specific override differs in its sort order in such a way,
49+
/// that all elements are ordered by their <see cref="CultureInfo.TwoLetterISOLanguageName" />t.
50+
/// </remarks>
51+
/// <param name="other"></param>
52+
/// <returns></returns>
53+
protected virtual int CompareToInternal(IAlamoLanguageDefinition other)
54+
{
55+
return string.Compare(Culture.TwoLetterISOLanguageName, other.Culture.TwoLetterISOLanguageName,
56+
StringComparison.Ordinal);
57+
}
58+
59+
/// <summary>
60+
/// Determines whether the specified object is equal to the current object.
61+
/// </summary>
62+
/// <param name="other"></param>
63+
/// <returns></returns>
64+
protected virtual bool EqualsInternal(IAlamoLanguageDefinition other)
65+
{
66+
return CompareTo(other) == 0;
67+
}
68+
69+
/// <summary>
70+
/// Serves as the default hash function.
71+
/// </summary>
72+
/// <remarks>
73+
/// The default implementation does intentionally create hash conflicts between identical language definitions,
74+
/// e.g. using the same <see cref="LanguageIdentifier" /> and <see cref="Culture" /> for two different derived classes.
75+
/// </remarks>
76+
/// <returns></returns>
77+
protected virtual int GetHashCodeInternal()
78+
{
79+
unchecked
80+
{
81+
return (ConfiguredLanguageIdentifier.GetHashCode() * 397) ^ Culture.GetHashCode();
82+
}
83+
}
84+
85+
/// <inheritdoc />
86+
public override bool Equals(object? obj)
87+
{
88+
if (obj is null) return false;
89+
90+
if (ReferenceEquals(this, obj)) return true;
91+
92+
return obj is IAlamoLanguageDefinition alamoLanguageDefinition && EqualsInternal(alamoLanguageDefinition);
93+
}
94+
95+
/// <inheritdoc />
96+
public override int GetHashCode()
97+
{
98+
return GetHashCodeInternal();
99+
}
100+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Globalization;
6+
using PG.StarWarsGame.Components.Localisation.Attributes;
7+
8+
namespace PG.StarWarsGame.Components.Localisation.Languages.BuiltIn;
9+
10+
/// <summary>
11+
/// The language definition for the Chinese language.
12+
/// </summary>
13+
/// <remarks>
14+
/// Officially supported by the Alamo Engine.
15+
/// </remarks>
16+
[ExcludeFromCodeCoverage]
17+
[OfficiallySupportedLanguage]
18+
public sealed class ChineseAlamoLanguageDefinition : AlamoLanguageDefinitionBase
19+
{
20+
/// <inheritdoc />
21+
protected override string ConfiguredLanguageIdentifier => "CHINESE";
22+
23+
/// <inheritdoc />
24+
protected override CultureInfo ConfiguredCulture => CultureInfo.GetCultureInfo("zh-CN");
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Globalization;
6+
using PG.StarWarsGame.Components.Localisation.Attributes;
7+
8+
namespace PG.StarWarsGame.Components.Localisation.Languages.BuiltIn;
9+
10+
/// <summary>
11+
/// The language definition for the English (US) language.
12+
/// </summary>
13+
/// <remarks>
14+
/// Officially supported by the Alamo Engine.<br />
15+
/// This language is the default game language and development language of all Alamo Engine games.
16+
/// </remarks>
17+
[ExcludeFromCodeCoverage]
18+
[DefaultLanguage]
19+
[OfficiallySupportedLanguage]
20+
public sealed class EnglishAlamoLanguageDefinition : AlamoLanguageDefinitionBase
21+
{
22+
/// <inheritdoc />
23+
protected override string ConfiguredLanguageIdentifier => "ENGLISH";
24+
25+
/// <inheritdoc />
26+
protected override CultureInfo ConfiguredCulture => CultureInfo.GetCultureInfo("en-US");
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Globalization;
6+
using PG.StarWarsGame.Components.Localisation.Attributes;
7+
8+
namespace PG.StarWarsGame.Components.Localisation.Languages.BuiltIn;
9+
10+
/// <summary>
11+
/// The language definition for the French language.
12+
/// </summary>
13+
/// <remarks>
14+
/// Officially supported by the Alamo Engine.
15+
/// </remarks>
16+
[ExcludeFromCodeCoverage]
17+
[OfficiallySupportedLanguage]
18+
public sealed class FrenchAlamoLanguageDefinition : AlamoLanguageDefinitionBase
19+
{
20+
/// <inheritdoc />
21+
protected override string ConfiguredLanguageIdentifier => "FRENCH";
22+
23+
/// <inheritdoc />
24+
protected override CultureInfo ConfiguredCulture => CultureInfo.GetCultureInfo("fr-FR");
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Globalization;
6+
using PG.StarWarsGame.Components.Localisation.Attributes;
7+
8+
namespace PG.StarWarsGame.Components.Localisation.Languages.BuiltIn;
9+
10+
/// <summary>
11+
/// The language definition for the German language.
12+
/// </summary>
13+
/// <remarks>
14+
/// Officially supported by the Alamo Engine.
15+
/// </remarks>
16+
[ExcludeFromCodeCoverage]
17+
[OfficiallySupportedLanguage]
18+
public sealed class GermanAlamoLanguageDefinition : AlamoLanguageDefinitionBase
19+
{
20+
/// <inheritdoc />
21+
protected override string ConfiguredLanguageIdentifier => "GERMAN";
22+
23+
/// <inheritdoc />
24+
protected override CultureInfo ConfiguredCulture => CultureInfo.GetCultureInfo("de-DE");
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Alamo Engine Tools and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Globalization;
6+
using PG.StarWarsGame.Components.Localisation.Attributes;
7+
8+
namespace PG.StarWarsGame.Components.Localisation.Languages.BuiltIn;
9+
10+
/// <summary>
11+
/// The language definition for the Italian language.
12+
/// </summary>
13+
/// <remarks>
14+
/// Officially supported by the Alamo Engine.
15+
/// </remarks>
16+
[ExcludeFromCodeCoverage]
17+
[OfficiallySupportedLanguage]
18+
public sealed class ItalianAlamoLanguageDefinition : AlamoLanguageDefinitionBase
19+
{
20+
/// <inheritdoc />
21+
protected override string ConfiguredLanguageIdentifier => "ITALIAN";
22+
23+
/// <inheritdoc />
24+
protected override CultureInfo ConfiguredCulture => CultureInfo.GetCultureInfo("it-IT");
25+
}

0 commit comments

Comments
 (0)