Browse Source
Merge pull request #7026 from axunonb/dev
Fix for culture-specific number formats with Volo.Abp.TextTemplating
pull/7062/head
maliming
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
28 additions and
1 deletions
-
framework/src/Volo.Abp.TextTemplating/Volo/Abp/TextTemplating/TemplateRenderer.cs
-
framework/test/Volo.Abp.TextTemplating.Tests/Volo/Abp/TextTemplating/SampleTemplates/ShowDecimalNumber.tpl
-
framework/test/Volo.Abp.TextTemplating.Tests/Volo/Abp/TextTemplating/TemplateRenderer_Tests.cs
-
framework/test/Volo.Abp.TextTemplating.Tests/Volo/Abp/TextTemplating/TestTemplateDefinitionProvider.cs
-
framework/test/Volo.Abp.TextTemplating.Tests/Volo/Abp/TextTemplating/TestTemplates.cs
-
framework/test/Volo.Abp.TextTemplating.Tests/Volo/Abp/TextTemplating/VirtualFiles/LocalizedTemplateContentReaderFactory_Tests.cs
|
|
|
@ -144,6 +144,7 @@ namespace Volo.Abp.TextTemplating |
|
|
|
} |
|
|
|
|
|
|
|
context.PushGlobal(scriptObject); |
|
|
|
context.PushCulture(System.Globalization.CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
return context; |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1 @@ |
|
|
|
{{ model.amount}} |
|
|
|
@ -91,6 +91,22 @@ namespace Volo.Abp.TextTemplating |
|
|
|
cultureName: "tr" |
|
|
|
)).ShouldBe("*BEGIN*Merhaba John, nasılsın?. Please click to the following link to get an email to reset your password!*END*"); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Get_Localized_Numbers() |
|
|
|
{ |
|
|
|
(await _templateRenderer.RenderAsync( |
|
|
|
TestTemplates.ShowDecimalNumber, |
|
|
|
new Dictionary<string, decimal>(new List<KeyValuePair<string, decimal>> {new("amount", 123.45M)}), |
|
|
|
cultureName: "en" |
|
|
|
)).ShouldBe("*BEGIN*123.45*END*"); |
|
|
|
|
|
|
|
(await _templateRenderer.RenderAsync( |
|
|
|
TestTemplates.ShowDecimalNumber, |
|
|
|
new Dictionary<string, decimal>(new List<KeyValuePair<string, decimal>> {new("amount", 123.45M)}), |
|
|
|
cultureName: "de" |
|
|
|
)).ShouldBe("*BEGIN*123,45*END*"); |
|
|
|
} |
|
|
|
|
|
|
|
private class WelcomeEmailModel |
|
|
|
{ |
|
|
|
|
|
|
|
@ -27,6 +27,14 @@ namespace Volo.Abp.TextTemplating |
|
|
|
isLayout: true |
|
|
|
).WithVirtualFilePath("/SampleTemplates/TestTemplateLayout1.tpl", true) |
|
|
|
); |
|
|
|
|
|
|
|
context.Add( |
|
|
|
new TemplateDefinition( |
|
|
|
TestTemplates.ShowDecimalNumber, |
|
|
|
localizationResource: typeof(TestLocalizationSource), |
|
|
|
layout: TestTemplates.TestTemplateLayout1 |
|
|
|
).WithVirtualFilePath("/SampleTemplates/ShowDecimalNumber.tpl", true) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -5,5 +5,6 @@ |
|
|
|
public const string WelcomeEmail = "WelcomeEmail"; |
|
|
|
public const string ForgotPasswordEmail = "ForgotPasswordEmail"; |
|
|
|
public const string TestTemplateLayout1 = "TestTemplateLayout1"; |
|
|
|
public const string ShowDecimalNumber = "ShowDecimalNumber"; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -23,7 +23,7 @@ namespace Volo.Abp.TextTemplating.VirtualFiles |
|
|
|
var localizedTemplateContentReaderFactory = new LocalizedTemplateContentReaderFactory( |
|
|
|
new PhysicalFileVirtualFileProvider( |
|
|
|
new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), |
|
|
|
@"Volo\Abp\TextTemplating\")))); |
|
|
|
"Volo", "Abp", "TextTemplating")))); |
|
|
|
|
|
|
|
var reader = await localizedTemplateContentReaderFactory.CreateAsync(_templateDefinitionManager.Get(TestTemplates.WelcomeEmail)); |
|
|
|
|
|
|
|
|