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

modify several module's SettingDefinitionProvider to support multi-lingual #2392

Merged
merged 7 commits into from
Dec 27, 2019
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
5 changes: 5 additions & 0 deletions framework/src/Volo.Abp.Emailing/Volo.Abp.Emailing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<None Remove="Volo\Abp\Emailing\Templates\DefaultEmailTemplates\*\*.tpl" />
</ItemGroup>

<ItemGroup>
<Content Remove="Volo\Abp\Emailing\Localization\*.json" />
<EmbeddedResource Include="Volo\Abp\Emailing\Localization\*.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Scriban" Version="2.1.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Emailing.Localization;
using Volo.Abp.Emailing.Templates;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
Expand Down Expand Up @@ -30,6 +31,13 @@ public override void ConfigureServices(ServiceConfigurationContext context)
options.FileSets.AddEmbedded<AbpEmailingModule>();
});

Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<EmailingResource>("en")
.AddVirtualJson("/Volo/Abp/Emailing/Localization");
});

Configure<AbpBackgroundJobOptions>(options =>
{
options.AddJob<BackgroundEmailSendingJob>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Volo.Abp.Emailing.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Settings;

namespace Volo.Abp.Emailing
Expand All @@ -11,16 +13,62 @@ internal class EmailSettingProvider : SettingDefinitionProvider
public override void Define(ISettingDefinitionContext context)
{
context.Add(
new SettingDefinition(EmailSettingNames.Smtp.Host, "127.0.0.1"),
new SettingDefinition(EmailSettingNames.Smtp.Port, "25"),
new SettingDefinition(EmailSettingNames.Smtp.UserName),
new SettingDefinition(EmailSettingNames.Smtp.Password, isEncrypted: true),
new SettingDefinition(EmailSettingNames.Smtp.Domain),
new SettingDefinition(EmailSettingNames.Smtp.EnableSsl, "false"),
new SettingDefinition(EmailSettingNames.Smtp.UseDefaultCredentials, "true"),
new SettingDefinition(EmailSettingNames.DefaultFromAddress, "[email protected]"),
new SettingDefinition(EmailSettingNames.DefaultFromDisplayName, "ABP application")
new SettingDefinition(
EmailSettingNames.Smtp.Host,
"127.0.0.1",
L("DisplayName:Abp.Mailing.Smtp.Host"),
L("Description:Abp.Mailing.Smtp.Host")),

new SettingDefinition(EmailSettingNames.Smtp.Port,
"25",
L("DisplayName:Abp.Mailing.Smtp.Port"),
L("Description:Abp.Mailing.Smtp.Port")),

new SettingDefinition(
EmailSettingNames.Smtp.UserName,
displayName: L("DisplayName:Abp.Mailing.Smtp.UserName"),
description: L("Description:Abp.Mailing.Smtp.UserName")),

new SettingDefinition(
EmailSettingNames.Smtp.Password,
displayName:
L("DisplayName:Abp.Mailing.Smtp.Password"),
description: L("Description:Abp.Mailing.Smtp.Password"),
isEncrypted: true),

new SettingDefinition(
EmailSettingNames.Smtp.Domain,
displayName: L("DisplayName:Abp.Mailing.Smtp.Domain"),
description: L("Description:Abp.Mailing.Smtp.Domain")),

new SettingDefinition(
EmailSettingNames.Smtp.EnableSsl,
"false",
L("DisplayName:Abp.Mailing.Smtp.EnableSsl"),
L("Description:Abp.Mailing.Smtp.EnableSsl")),

new SettingDefinition(
EmailSettingNames.Smtp.UseDefaultCredentials,
"true",
L("DisplayName:Abp.Mailing.Smtp.UseDefaultCredentials"),
L("Description:Abp.Mailing.Smtp.UseDefaultCredentials")),

new SettingDefinition(
EmailSettingNames.DefaultFromAddress,
"[email protected]",
L("DisplayName:Abp.Mailing.DefaultFromAddress"),
L("Description:Abp.Mailing.DefaultFromAddress")),

new SettingDefinition(EmailSettingNames.DefaultFromDisplayName,
"ABP application",
L("DisplayName:Abp.Mailing.DefaultFromDisplayName"),
L("Description:Abp.Mailing.DefaultFromDisplayName"))
);
}

private static LocalizableString L(string name)
{
return LocalizableString.Create<EmailingResource>(name);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Volo.Abp.Localization;

namespace Volo.Abp.Emailing.Localization
{
[LocalizationResourceName("AbpEmailing")]
public class EmailingResource
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"culture": "en",
"texts": {
"DisplayName:Abp.Mailing.DefaultFromAddress": "Default from address",
"DisplayName:Abp.Mailing.DefaultFromDisplayName": "Default from display name",
"DisplayName:Abp.Mailing.Smtp.Host": "Host",
"DisplayName:Abp.Mailing.Smtp.Port": "Port",
"DisplayName:Abp.Mailing.Smtp.UserName": "User name",
"DisplayName:Abp.Mailing.Smtp.Password": "Password",
"DisplayName:Abp.Mailing.Smtp.Domain": "Domain",
"DisplayName:Abp.Mailing.Smtp.EnableSsl": "Enable SSL",
"DisplayName:Abp.Mailing.Smtp.UseDefaultCredentials": "Use default credentials",
"Description:Abp.Mailing.DefaultFromAddress": "The default from address",
"Description:Abp.Mailing.DefaultFromDisplayName": "The default from display name",
"Description:Abp.Mailing.Smtp.Host": "The name or IP address of the host used for SMTP transactions.",
"Description:Abp.Mailing.Smtp.Port": "The port used for SMTP transactions.",
"Description:Abp.Mailing.Smtp.UserName": "User name associated with the credentials.",
"Description:Abp.Mailing.Smtp.Password": "The password for the user name associated with the credentials.",
"Description:Abp.Mailing.Smtp.Domain": "The domain or computer name that verifies the credentials.",
"Description:Abp.Mailing.Smtp.EnableSsl": "Whether the SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection.",
"Description:Abp.Mailing.Smtp.UseDefaultCredentials": "Whether the DefaultCredentials are sent with requests."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"culture": "zh-Hans",
"texts": {
"DisplayName:Abp.Mailing.DefaultFromAddress": "默认发件人地址",
"DisplayName:Abp.Mailing.DefaultFromDisplayName": "默认发件人名字",
"DisplayName:Abp.Mailing.Smtp.Host": "主机",
"DisplayName:Abp.Mailing.Smtp.Port": "端口",
"DisplayName:Abp.Mailing.Smtp.UserName": "用户名",
"DisplayName:Abp.Mailing.Smtp.Password": "密码",
"DisplayName:Abp.Mailing.Smtp.Domain": "域",
"DisplayName:Abp.Mailing.Smtp.EnableSsl": "启用SSL",
"DisplayName:Abp.Mailing.Smtp.UseDefaultCredentials": "使用默认凭据",
"Description:Abp.Mailing.DefaultFromAddress": "默认的发件人地址.",
"Description:Abp.Mailing.DefaultFromDisplayName": "默认的发件人名字.",
"Description:Abp.Mailing.Smtp.Host": "SMTP 事务的主机名或主机 IP 地址.",
"Description:Abp.Mailing.Smtp.Port": "SMTP 事务的端口.",
"Description:Abp.Mailing.Smtp.UserName": "凭据关联的用户名.",
"Description:Abp.Mailing.Smtp.Password": "凭据关联的用户名的密码.",
"Description:Abp.Mailing.Smtp.Domain": "验证凭据的域名或计算机名.",
"Description:Abp.Mailing.Smtp.EnableSsl": "指定 SmtpClient 是否使用安全套接字层 (SSL) 加密连接.",
"Description:Abp.Mailing.Smtp.UseDefaultCredentials": "控制默认凭据是否随请求一起发送."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Volo\Abp\Localization\Resources\**\*.json" />
<EmbeddedResource Include="Volo\Abp\Localization\Resources\**\*.json" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Volo.Abp.Localization.Resources.AbpValidation;
using Volo.Abp.Localization.Resources.AbpLocalization;
using Volo.Abp.Localization.Resources.AbpValidation;
using Volo.Abp.Modularity;
using Volo.Abp.Settings;
using Volo.Abp.VirtualFileSystem;
Expand Down Expand Up @@ -27,10 +28,16 @@ public override void ConfigureServices(ServiceConfigurationContext context)
.Resources
.Add<DefaultResource>("en");

//TODO: Obsolete, Remove in the future version
options
.Resources
.Add<AbpValidationResource>("en")
.AddVirtualJson("/Localization/Resources/AbpValidation");
.AddVirtualJson("/Volo/Abp/Validation/Localization");//load from Volo.Abp.Validation

options
.Resources
.Add<AbpLocalizationResource>("en")
.AddVirtualJson("/Localization/Resources/AbpLocalization");
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Volo.Abp.Settings;
using Volo.Abp.Localization.Resources.AbpValidation;
using Volo.Abp.Settings;

namespace Volo.Abp.Localization
{
Expand All @@ -7,8 +8,17 @@ public class LocalizationSettingProvider : SettingDefinitionProvider
public override void Define(ISettingDefinitionContext context)
{
context.Add(
new SettingDefinition(LocalizationSettingNames.DefaultLanguage, "en", isVisibleToClients: true)
new SettingDefinition(LocalizationSettingNames.DefaultLanguage,
"en",
L("DisplayName:Abp.Localization.DefaultLanguage"),
L("Description:Abp.Localization.DefaultLanguage"),
isVisibleToClients: true)
);
}

private static LocalizableString L(string name)
{
return LocalizableString.Create<AbpValidationResource>(name);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Volo.Abp.Localization.Resources.AbpLocalization
{
[LocalizationResourceName("AbpLocalization")]
public class AbpLocalizationResource
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"culture": "en",
"texts": {
"DisplayName:Abp.Localization.DefaultLanguage": "Default language",
"Description:Abp.Localization.DefaultLanguage": "The default language of the application."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"culture": "zh-Hans",
"texts": {
"DisplayName:Abp.Localization.DefaultLanguage": "默认语言",
"Description:Abp.Localization.DefaultLanguage": "应用程序的默认语言."
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace Volo.Abp.Localization.Resources.AbpValidation
using System;

namespace Volo.Abp.Localization.Resources.AbpValidation
{
//TODO: Move to Volo.Abp.Validation!

[LocalizationResourceName("AbpValidation")]
[Obsolete("This resource is obsolete.Use Volo.Abp.Validation.Localization.AbpValidationResource instead.", false)]
public class AbpValidationResource
{

Expand Down
8 changes: 7 additions & 1 deletion framework/src/Volo.Abp.Validation/Volo.Abp.Validation.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\common.props" />

Expand All @@ -13,8 +13,14 @@
<RootNamespace />
</PropertyGroup>

<ItemGroup>
<None Remove="Volo\Abp\Validation\Localization\*.json" />
<EmbeddedResource Include="Volo\Abp\Validation\Localization\*.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Validation.Localization;
using Volo.Abp.VirtualFileSystem;

namespace Volo.Abp.Validation
{
[DependsOn(
typeof(AbpLocalizationModule)
)]
public class AbpValidationModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.OnRegistred(ValidationInterceptorRegistrar.RegisterIfNeeded);
AutoAddObjectValidationContributors(context.Services);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpValidationResource>();
});

Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Add<AbpValidationResource>("en")
.AddVirtualJson("/Volo/Abp/Validation/Localization");
});
}

private static void AutoAddObjectValidationContributors(IServiceCollection services)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Volo.Abp.Localization;

namespace Volo.Abp.Validation.Localization
{
[LocalizationResourceName("AbpValidation")]
public class AbpValidationResource
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"ThisFieldMustBeAStringWithAMaximumLengthOf{0}": "字段必须是长度为{0}的字符串.",
"ThisFieldMustBeAStringWithAMinimumLengthOf{1}AndAMaximumLengthOf{0}": "字段必须是最小长度为{1}并且最大长度{*}的字符串.",
"ThisFieldIsNotAValidFullyQualifiedHttpHttpsOrFtpUrl": "字段{0}不是有效的完全限定的http,https或ftp URL.",
"ThisFieldIsInvalid.": "字段是无效值."
"ThisFieldIsInvalid.": "该字段无效."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"PasswordChanged": "Password changed",
"NewPasswordConfirmFailed": "Please confirm the new password.",
"Manage": "Manage",
"ManageYourProfile": "Manage your profile"
"ManageYourProfile": "Manage your profile",
"DisplayName:Abp.Account.IsSelfRegistrationEnabled": "Is self-registration enabled",
"Description:Abp.Account.IsSelfRegistrationEnabled": "Whether a user can register the account by him or herself.",
"DisplayName:Abp.Account.EnableLocalLogin": "Authenticate with a local account",
"Description:Abp.Account.EnableLocalLogin": "Indicates if Server will allow users to authenticate with a local account."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"PasswordChanged": "修改密码",
"NewPasswordConfirmFailed": "请确认新密码",
"Manage": "管理",
"ManageYourProfile": "管理你的个人资料"
"ManageYourProfile": "管理你的个人资料",
"DisplayName:Abp.Account.IsSelfRegistrationEnabled": "启用自行注册",
"Description:Abp.Account.IsSelfRegistrationEnabled": "是否允许用户自行注册帐户.",
"DisplayName:Abp.Account.EnableLocalLogin": "使用本地帐户进行身份验证",
"Description:Abp.Account.EnableLocalLogin": "服务器是否将允许用户使用本地帐户进行身份验证。"
}
}
Loading