This repository was archived by the owner on Nov 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathStringLocalizerOfT.cs
More file actions
67 lines (57 loc) · 2.09 KB
/
StringLocalizerOfT.cs
File metadata and controls
67 lines (57 loc) · 2.09 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace Microsoft.Extensions.Localization
{
/// <summary>
/// Provides strings for <typeparamref name="TResourceSource"/>.
/// </summary>
/// <typeparam name="TResourceSource">The <see cref="Type"/> to provide strings for.</typeparam>
public class StringLocalizer<TResourceSource> : IStringLocalizer<TResourceSource>
{
private IStringLocalizer _localizer;
/// <summary>
/// Creates a new <see cref="StringLocalizer{TResourceSource}"/>.
/// </summary>
/// <param name="factory">The <see cref="IStringLocalizerFactory"/> to use.</param>
public StringLocalizer(IStringLocalizerFactory factory)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}
_localizer = factory.Create(typeof(TResourceSource));
}
/// <inheritdoc />
public virtual IStringLocalizer WithCulture(CultureInfo culture) => _localizer.WithCulture(culture);
/// <inheritdoc />
public virtual LocalizedString this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _localizer[name];
}
}
/// <inheritdoc />
public virtual LocalizedString this[string name, params object[] arguments]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return _localizer[name, arguments];
}
}
/// <inheritdoc />
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) =>
_localizer.GetAllStrings(includeParentCultures);
}
}