mirror of https://github.com/abpframework/abp.git
6 changed files with 80 additions and 16 deletions
@ -0,0 +1,50 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using Scriban; |
||||
|
using Scriban.Runtime; |
||||
|
using Scriban.Syntax; |
||||
|
|
||||
|
namespace Volo.Abp.TextTemplating |
||||
|
{ |
||||
|
public class TemplateLocalizer : IScriptCustomFunction |
||||
|
{ |
||||
|
private readonly IStringLocalizer _localizer; |
||||
|
|
||||
|
public TemplateLocalizer(IStringLocalizer localizer) |
||||
|
{ |
||||
|
_localizer = localizer; |
||||
|
} |
||||
|
|
||||
|
public object Invoke(TemplateContext context, ScriptNode callerContext, ScriptArray arguments, |
||||
|
ScriptBlockStatement blockStatement) |
||||
|
{ |
||||
|
return GetString(arguments); |
||||
|
} |
||||
|
|
||||
|
public ValueTask<object> InvokeAsync(TemplateContext context, ScriptNode callerContext, ScriptArray arguments, |
||||
|
ScriptBlockStatement blockStatement) |
||||
|
{ |
||||
|
return new ValueTask<object>(GetString(arguments)); |
||||
|
} |
||||
|
|
||||
|
private string GetString(ScriptArray arguments) |
||||
|
{ |
||||
|
if (arguments.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return string.Empty; |
||||
|
} |
||||
|
|
||||
|
var name = arguments[0]; |
||||
|
if (name == null || name.ToString().IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
return string.Empty; |
||||
|
} |
||||
|
|
||||
|
var args = arguments.Skip(1).Where(x => x != null && !x.ToString().IsNullOrWhiteSpace()).ToArray(); |
||||
|
return args.Any() ? _localizer[name.ToString(), args] : _localizer[name.ToString()]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,6 +1,7 @@ |
|||||
{ |
{ |
||||
"culture": "en", |
"culture": "en", |
||||
"texts": { |
"texts": { |
||||
"HelloText": "Hello" |
"HelloText": "Hello {0}", |
||||
} |
"HowAreYou": "how are you?" |
||||
} |
} |
||||
|
} |
||||
|
|||||
@ -1,6 +1,7 @@ |
|||||
{ |
{ |
||||
"culture": "tr", |
"culture": "tr", |
||||
"texts": { |
"texts": { |
||||
"HelloText": "Merhaba" |
"HelloText": "Merhaba {0}", |
||||
} |
"HowAreYou": "nasılsın?" |
||||
} |
} |
||||
|
} |
||||
|
|||||
@ -1 +1 @@ |
|||||
{{L "HelloText"}}. Please click to the following link to get an email to reset your password! |
{{L "HelloText" model.name}}, {{L "HowAreYou" }}. Please click to the following link to get an email to reset your password! |
||||
Loading…
Reference in new issue