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

feat(18n): Support I18 and Refactor Exception #330

Merged
merged 45 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ead4e94
feat: Add Globalization
zhenlei520 Oct 8, 2022
9398da4
feat: Add Localization
zhenlei520 Oct 11, 2022
762644f
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Oct 11, 2022
3834f69
fix: Fix Localization
zhenlei520 Oct 12, 2022
f11fc51
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Oct 14, 2022
4e2c792
feat(Localization): Add Localization
zhenlei520 Oct 17, 2022
f05376a
feat: Add Localization
zhenlei520 Oct 18, 2022
a9fcf5a
feat(Localization): Add Languages
zhenlei520 Oct 18, 2022
73faaff
chore: global using
zhenlei520 Oct 19, 2022
ab36063
feat: Add I18N
zhenlei520 Oct 19, 2022
30e70d2
feat: Support I18N
zhenlei520 Oct 19, 2022
1dd1f42
feat: AddII18N
zhenlei520 Oct 31, 2022
e64cd7c
rename: Const -> Constant
zhenlei520 Oct 31, 2022
b18b2a5
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Oct 31, 2022
6a28069
chore: format code
zhenlei520 Oct 31, 2022
f7b8925
chore: ErrorCode access level changed to private
zhenlei520 Oct 31, 2022
8f99031
feat(Exception): Add Exception
zhenlei520 Nov 1, 2022
da8c5a6
refactor(Exception): Refactor Exception
zhenlei520 Nov 2, 2022
93651f2
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Nov 2, 2022
d489289
refactor(Exception): Refactor Exception
zhenlei520 Nov 2, 2022
998d2f0
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Nov 2, 2022
53c9b15
feat: Support Exception
zhenlei520 Nov 3, 2022
b949a6d
feat(Exception): Modify Exception
zhenlei520 Nov 3, 2022
c88a0bf
feat(Globalization): Add I18N
zhenlei520 Nov 4, 2022
6917d19
feat(I18n): Support I18n
zhenlei520 Nov 7, 2022
3df9872
feat(I18N): Adjust I18n.Dcc
zhenlei520 Nov 7, 2022
3b69b03
feat: Add I18N on Blazor Server
zhenlei520 Nov 7, 2022
282245f
feat(I18N): support WebAssembly
zhenlei520 Nov 8, 2022
3a0b87b
feat(I18n): Adjust I18n Support Embedded resources
zhenlei520 Nov 8, 2022
3773064
feat: Caller Support I18N
zhenlei520 Nov 9, 2022
dc4d3e6
feat: Support FluentValidation
zhenlei520 Nov 9, 2022
8f3fbaa
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Nov 9, 2022
52aaa75
feat(I18n): Support I18N
zhenlei520 Nov 9, 2022
60aec79
fix: Fix unit test issues
zhenlei520 Nov 10, 2022
10d39ab
rename: I18N -> I18n
zhenlei520 Nov 10, 2022
cce7b86
chore: Modify code bad smell
zhenlei520 Nov 10, 2022
7bc010e
chore: Modify code bad smell
zhenlei520 Nov 10, 2022
aa49bef
chore: deal with bad taste
zhenlei520 Nov 10, 2022
7cec513
rename: I18n -> I18N
zhenlei520 Nov 10, 2022
59d80b2
chore: fix bad code smell
zhenlei520 Nov 10, 2022
9827b81
chore: Adjust the default Culture
zhenlei520 Nov 11, 2022
2eebad0
chore: Optimize the experience
zhenlei520 Nov 11, 2022
85f6841
chore: fix bad code smell
zhenlei520 Nov 11, 2022
93951b9
Merge branch 'main' of https://github.com/masastack/MASA.Framework in…
zhenlei520 Nov 14, 2022
c8b21a3
rename: I18N -> I18n
zhenlei520 Nov 14, 2022
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
210 changes: 161 additions & 49 deletions Masa.Framework.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Masa.Framework.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Masa/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DaprProcess/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MasaConfigurationProvider/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dapr/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

// ReSharper disable once CheckNamespace

namespace Microsoft.Extensions.DependencyInjection;

public static class ConfigurationExtensions
{
public static Dictionary<string, string> ConvertToDictionary(this IConfiguration configuration)
{
var data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
GetData(configuration, configuration.GetChildren(), ref data);
return data;
}

private static void GetData(
IConfiguration configuration,
IEnumerable<IConfigurationSection> configurationSections,
ref Dictionary<string, string> dictionary)
{
foreach (var configurationSection in configurationSections)
{
var section = configuration.GetSection(configurationSection.Path);

var childrenSections = section.GetChildren()?.ToList() ?? new List<IConfigurationSection>();

if (!section.Exists() || !childrenSections.Any())
{
var key = section.Path;
if (!dictionary.ContainsKey(key))
{
dictionary.Add(key, configuration[section.Path]);
}
}
else
{
GetData(configuration, childrenSections, ref dictionary);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.Data.Constants;

public static class ErrorCode
{
public const string FRAMEWORK_PREFIX = "MF";

#region Type

/// <summary>
/// Internal service error
/// </summary>
private const string INTERNAL_SERVER = $"{FRAMEWORK_PREFIX}SVR";

/// <summary>
/// parameter validation error
/// </summary>
private const string ARGUMENT = $"{FRAMEWORK_PREFIX}ARG";

#endregion

#region Argument Verify

/// <summary>
/// '{PropertyName}' is not a valid email address.
/// </summary>
[Description("'{0}' is not a valid email address.")]
public const string EMAIL_VALIDATOR = $"{ARGUMENT}0001";

/// <summary>
/// '{PropertyName}' must be greater than or equal to '{ComparisonValue}'.
/// </summary>
[Description("'{0}' must be greater than or equal to '{1}'.")]
public const string GREATER_THAN_OR_EQUAL_VALIDATOR = $"{ARGUMENT}0002";

/// <summary>
/// '{PropertyName}' must be greater than '{ComparisonValue}'.
/// </summary>
[Description("'{0}' must be greater than '{1}'.")]
public const string GREATER_THAN_VALIDATOR = $"{ARGUMENT}0003";

/// <summary>
/// '{PropertyName}' must be between {MinLength} and {MaxLength} characters. You entered {TotalLength} characters.
/// </summary>
[Description("'{0}' must be between {1} and {2} characters. You entered {3} characters.")]
public const string LENGTH_VALIDATOR = $"{ARGUMENT}0004";

/// <summary>
/// The length of '{PropertyName}' must be at least {MinLength} characters. You entered {TotalLength} characters.
/// </summary>
[Description("The length of '{0}' must be at least {1} characters. You entered {2} characters.")]
public const string MINIMUM_LENGTH_VALIDATOR = $"{ARGUMENT}0005";

/// <summary>
/// The length of '{PropertyName}' must be {MaxLength} characters or fewer. You entered {TotalLength} characters.
/// </summary>
[Description("The length of '{0}' must be {1} characters or fewer. You entered {2} characters.")]
public const string MAXIMUM_LENGTH_VALIDATOR = $"{ARGUMENT}0006";

/// <summary>
/// '{PropertyName}' must be less than or equal to '{ComparisonValue}'.
/// </summary>
[Description("'{0}' must be less than or equal to '{1}'.")]
public const string LESS_THAN_OR_EQUAL_VALIDATOR = $"{ARGUMENT}0007";

/// <summary>
/// '{PropertyName}' must be less than '{ComparisonValue}'.
/// </summary>
[Description("'{0}' must be less than '{1}'.")]
public const string LESS_THAN_VALIDATOR = $"{ARGUMENT}0008";

/// <summary>
/// '{PropertyName}' must not be empty.
/// </summary>
[Description("'{0}' must not be empty.")]
public const string NOT_EMPTY_VALIDATOR = $"{ARGUMENT}0009";

/// <summary>
/// '{PropertyName}' must not be equal to '{ComparisonValue}'.
/// </summary>
[Description("'{0}' must not be equal to '{1}'.")]
public const string NOT_EQUAL_VALIDATOR = $"{ARGUMENT}0010";

/// <summary>
/// '{PropertyName}' must not be empty.
/// </summary>
[Description("'{0}' must not be empty.")]
public const string NOT_NULL_VALIDATOR = $"{ARGUMENT}0011";

/// <summary>
/// The specified condition was not met for '{0}'.
/// </summary>
[Description("The specified condition was not met for '{0}'.")]
public const string PREDICATE_VALIDATOR = $"{ARGUMENT}0012";

/// <summary>
/// The specified condition was not met for '{0}'.
/// </summary>
[Description("The specified condition was not met for '{0}'.")]
public const string ASYNC_PREDICATE_VALIDATOR = $"{ARGUMENT}0013";

/// <summary>
/// '{PropertyName}' is not in the correct format.
/// </summary>
[Description("'{0}' is not in the correct format.")]
public const string REGULAR_EXPRESSION_VALIDATOR = $"{ARGUMENT}0014";

/// <summary>
/// '{PropertyName}' must be equal to '{ComparisonValue}'.
/// </summary>
[Description("'{0}' must be equal to '{1}'.")]
public const string EQUAL_VALIDATOR = $"{ARGUMENT}0015";

/// <summary>
/// '{PropertyName}' must be {MaxLength} characters in length. You entered {TotalLength} characters.
/// </summary>
[Description("'{0}' must be {1} characters in length. You entered {2} characters.")]
public const string EXACT_LENGTH_VALIDATOR = $"{ARGUMENT}0016";

/// <summary>
/// '{PropertyName}' must be between {From} and {To}. You entered {PropertyValue}.
/// </summary>
[Description("'{0}' must be between {1} and {2}. You entered {3}.")]
public const string INCLUSIVE_BETWEEN_VALIDATOR = $"{ARGUMENT}0017";

/// <summary>
/// '{PropertyName}' must be between {From} and {To} (exclusive). You entered {PropertyValue}.
/// </summary>
[Description("'{0}' must be between {1} and {2} (exclusive). You entered {3}.")]
public const string EXCLUSIVE_BETWEEN_VALIDATOR = $"{ARGUMENT}0018";

/// <summary>
/// '{PropertyName}' cannot be null and empty.
/// </summary>
[Description("'{0}' cannot be null and empty.")]
public const string NOT_NULL_AND_EMPTY_VALIDATOR = $"{ARGUMENT}0019";

/// <summary>
/// '{PropertyName}' must not be more than {ExpectedPrecision} digits in total, with allowance for {ExpectedScale} decimals. {Digits} digits and {ActualScale} decimals were found.
/// </summary>
[Description("'{0}' must not be more than {1} digits in total, with allowance for {2} decimals. {3} digits and {4} decimals were found.")]
public const string SCALE_PRECISION_VALIDATOR = $"{ARGUMENT}0020";

/// <summary>
/// '{PropertyName}' must be empty.
/// </summary>
[Description("'{0}' must be empty.")]
public const string EMPTY_VALIDATOR = $"{ARGUMENT}0021";

/// <summary>
/// '{PropertyName}' must be empty.
/// </summary>
[Description("'{0}' must be empty.")]
public const string NULL_VALIDATOR = $"{ARGUMENT}0022";

/// <summary>
/// '{0}' has a range of values which does not include '{1}'.
/// </summary>
[Description("'{0}' has a range of values which does not include '{1}'.")]
public const string ENUM_VALIDATOR = $"{ARGUMENT}0023";

/// <summary>
/// '{PropertyName}' must be between {MinLength} and {MaxLength} characters.
/// </summary>
[Description("'{0}' must be between {1} and {2} characters.")]
public const string LENGTH_SIMPLE = $"{ARGUMENT}0024";

/// <summary>
/// The length of '{PropertyName}' must be at least {MinLength} characters.
/// </summary>
[Description("The length of '{0}' must be at least {1} characters.")]
public const string MINIMUM_LENGTH_SIMPLE = $"{ARGUMENT}0025";

/// <summary>
/// The length of '{0}' must be {1} characters or fewer.
/// </summary>
[Description("The length of '{PropertyName}' must be {MaxLength} characters or fewer.")]
public const string MAXIMUM_LENGTH_SIMPLE = $"{ARGUMENT}0026";

/// <summary>
/// '{0}' must be {1} characters in length.
/// </summary>
[Description("'{PropertyName}' must be {MaxLength} characters in length.")]
public const string EXACT_LENGTH_SIMPLE = $"{ARGUMENT}0027";

/// <summary>
/// '{0}' must be between {1} and {2}.
/// </summary>
[Description("'{PropertyName}' must be between {From} and {To}.")]
public const string INCLUSIVE_BETWEEN_SIMPLE = $"{ARGUMENT}0028";

/// <summary>
/// '{PropertyName}' cannot be Null or empty collection.
/// </summary>
[Description("'{0}' cannot be Null or empty collection.")]
public const string NOT_NULL_AND_EMPTY_COLLECTION_VALIDATOR = $"{ARGUMENT}0029";

/// <summary>
/// '{PropertyName}' cannot be Null or whitespace.
/// </summary>
[Description("'{0}' cannot be Null or whitespace.")]
public const string NOT_NULL_AND_WHITESPACE_VALIDATOR = $"{ARGUMENT}0030";

/// <summary>
/// '{PropertyName}' cannot contain {Content}.
/// </summary>
[Description("'{0}' cannot contain {1}.")]
public const string NOT_CONTAIN_VALIDATOR = $"{ARGUMENT}0031";

/// <summary>
/// '{PropertyName}' must be greater than or equal to '{min}' and less than or equal to '{max}'.
/// </summary>
[Description("'{0}' must be greater than or equal to '{1}' and less than or equal to '{2}'.")]
public const string OUT_OF_RANGE_VALIDATOR = $"{ARGUMENT}0032";

#endregion

#region Other

/// <summary>
/// Internal service error
/// </summary>
[Description("Internal service error")]
public const string INTERNAL_SERVER_ERROR = $"{INTERNAL_SERVER}0001";

#endregion

private static readonly Dictionary<string, string?> _errorCodeMessageDictionary = new();

static ErrorCode()
{
var classType = typeof(ErrorCode);
var fields = classType.GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (var field in fields)
{
var errorMessage = AttributeUtils.GetDescriptionByField(field);

_errorCodeMessageDictionary.Add(field.GetRawConstantValue()!.ToString()!, errorMessage);
}
}

public static string? GetErrorMessage(string errorCode)
{
if (_errorCodeMessageDictionary.TryGetValue(errorCode, out string? errorMessage))
return errorMessage;

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Utils\Extensions\Masa.Utils.Extensions.DotNet\Masa.Utils.Extensions.DotNet.csproj" />
<ProjectReference Include="..\Masa.BuildingBlocks.Data.Contracts\Masa.BuildingBlocks.Data.Contracts.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj"/>
<ProjectReference Include="..\..\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj" />
<ProjectReference Include="..\..\Exception\Masa.BuildingBlocks.Exceptions\Masa.BuildingBlocks.Exceptions.csproj" />
</ItemGroup>

</Project>
Loading