Make standard layouts inline localized. Also, set IsInlineLocalized on WithVirtualFilePath

pull/3831/head
Halil İbrahim Kalkan 5 years ago
parent c59435efd6
commit a94cdf7b37

@ -18,6 +18,8 @@
"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."
"Description:Abp.Mailing.Smtp.UseDefaultCredentials": "Whether the DefaultCredentials are sent with requests.",
"TextTemplate:StandardEmailTemplates.Layout": "Default email layout template",
"TextTemplate:StandardEmailTemplates.Message": "Simple message template for emails"
}
}

@ -1,25 +1,27 @@
using Volo.Abp.TextTemplating;
using Volo.Abp.Emailing.Localization;
using Volo.Abp.Localization;
using Volo.Abp.TextTemplating;
namespace Volo.Abp.Emailing.Templates
{
public class DefaultEmailTemplateProvider : TemplateDefinitionProvider
public class StandardEmailTemplateDefinitionProvider : TemplateDefinitionProvider
{
public override void Define(ITemplateDefinitionContext context)
{
context.Add(
new TemplateDefinition(
StandardEmailTemplates.Layout,
defaultCultureName: "en",
displayName: LocalizableString.Create<EmailingResource>("TextTemplate:StandardEmailTemplates.Layout"),
isLayout: true
).WithVirtualFilePath("/Volo/Abp/Emailing/Templates/Layout")
).WithVirtualFilePath("/Volo/Abp/Emailing/Templates/Layout.tpl", true)
);
context.Add(
new TemplateDefinition(
StandardEmailTemplates.Message,
defaultCultureName: "en",
displayName: LocalizableString.Create<EmailingResource>("TextTemplate:StandardEmailTemplates.Message"),
layout: StandardEmailTemplates.Layout
).WithVirtualFilePath("/Volo/Abp/Emailing/Templates/Message")
).WithVirtualFilePath("/Volo/Abp/Emailing/Templates/Message.tpl", true)
);
}
}

@ -8,10 +8,13 @@ namespace Volo.Abp.TextTemplating
{
public static TemplateDefinition WithVirtualFilePath(
[NotNull] this TemplateDefinition templateDefinition,
[NotNull] string virtualPath)
[NotNull] string virtualPath,
bool isInlineLocalized)
{
Check.NotNull(templateDefinition, nameof(templateDefinition));
templateDefinition.IsInlineLocalized = isInlineLocalized;
return templateDefinition.WithProperty(
VirtualFileTemplateContentContributor.VirtualPathPropertyName,
virtualPath

@ -5,7 +5,6 @@ using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.VirtualFileSystem;
namespace Volo.Abp.TextTemplating
{
@ -79,38 +78,9 @@ namespace Volo.Abp.TextTemplating
{
provider.PostDefine(context);
}
SetIsInlineLocalized(
templates,
scope.ServiceProvider
);
}
return templates;
}
protected virtual void SetIsInlineLocalized(
Dictionary<string, TemplateDefinition> templates,
IServiceProvider serviceProvider)
{
var virtualFileProvider = serviceProvider.GetRequiredService<IVirtualFileProvider>();
foreach (var templateDefinition in templates.Values)
{
var virtualPath = templateDefinition.GetVirtualFilePathOrNull();
if (virtualPath == null)
{
continue;
}
var fileInfo = virtualFileProvider.GetFileInfo(virtualPath);
if (!fileInfo.Exists)
{
throw new AbpException("Could not find a file/folder at the location: " + virtualPath);
}
templateDefinition.IsInlineLocalized = !fileInfo.IsDirectory;
}
}
}
}

@ -10,7 +10,7 @@ namespace Volo.Abp.TextTemplating
new TemplateDefinition(
TestTemplates.WelcomeEmail,
defaultCultureName: "en"
).WithVirtualFilePath("/SampleTemplates/WelcomeEmail")
).WithVirtualFilePath("/SampleTemplates/WelcomeEmail", false)
);
context.Add(
@ -18,14 +18,14 @@ namespace Volo.Abp.TextTemplating
TestTemplates.ForgotPasswordEmail,
localizationResource: typeof(TestLocalizationSource),
layout: TestTemplates.TestTemplateLayout1
).WithVirtualFilePath("/SampleTemplates/ForgotPasswordEmail.tpl")
).WithVirtualFilePath("/SampleTemplates/ForgotPasswordEmail.tpl", true)
);
context.Add(
new TemplateDefinition(
TestTemplates.TestTemplateLayout1,
isLayout: true
).WithVirtualFilePath("/SampleTemplates/TestTemplateLayout1.tpl")
).WithVirtualFilePath("/SampleTemplates/TestTemplateLayout1.tpl", true)
);
}
}

Loading…
Cancel
Save