-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomLocalizer.cs
46 lines (40 loc) · 1.3 KB
/
CustomLocalizer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using System.Globalization;
using VoiConShop.Resources;
namespace VoiConShop
{
public sealed class CustomLocalizer : StringLocalizer<Common>
{
private readonly IStringLocalizer _internalLocalizer;
public CustomLocalizer(IStringLocalizerFactory factory, IHttpContextAccessor httpContextAccessor) : base(factory)
{
CurrentLanguage = httpContextAccessor.HttpContext.GetRouteValue("lang") as string;
if (string.IsNullOrEmpty(CurrentLanguage))
{
CurrentLanguage = "en";
}
if (CurrentLanguage == "ee")
{
CurrentLanguage = "et";
}
_internalLocalizer = WithCulture(new CultureInfo(CurrentLanguage));
}
public override LocalizedString this[string name, params object[] arguments]
{
get
{
return _internalLocalizer[name, arguments];
}
}
public override LocalizedString this[string name]
{
get
{
return _internalLocalizer[name];
}
}
public string CurrentLanguage { get; set; }
}
}