9
9
namespace Microsoft . AspNet . Mvc . Localization
10
10
{
11
11
/// <summary>
12
- /// An <see cref="IHtmlLocalizer"/> that uses the <see cref="IStringLocalizer"/> to provide localized HTML content.
13
- /// This service just encodes the arguments but not the resource string .
12
+ /// An <see cref="IHtmlLocalizer"/> that uses the provided <see cref="IStringLocalizer"/> to do HTML-aware
13
+ /// localization of content .
14
14
/// </summary>
15
15
public class HtmlLocalizer : IHtmlLocalizer
16
16
{
17
- private IStringLocalizer _localizer ;
17
+ private readonly IStringLocalizer _localizer ;
18
18
19
19
/// <summary>
20
20
/// Creates a new <see cref="HtmlLocalizer"/>.
@@ -31,109 +31,68 @@ public HtmlLocalizer(IStringLocalizer localizer)
31
31
}
32
32
33
33
/// <inheritdoc />
34
- public virtual LocalizedString this [ string key ]
34
+ public virtual LocalizedHtmlString this [ string name ]
35
35
{
36
36
get
37
37
{
38
- if ( key == null )
38
+ if ( name == null )
39
39
{
40
- throw new ArgumentNullException ( nameof ( key ) ) ;
40
+ throw new ArgumentNullException ( nameof ( name ) ) ;
41
41
}
42
42
43
- return _localizer [ key ] ;
43
+ return ToHtmlString ( _localizer [ name ] ) ;
44
44
}
45
45
}
46
46
47
47
/// <inheritdoc />
48
- public virtual LocalizedString this [ string key , params object [ ] arguments ]
48
+ public virtual LocalizedHtmlString this [ string name , params object [ ] arguments ]
49
49
{
50
50
get
51
51
{
52
- if ( key == null )
52
+ if ( name == null )
53
53
{
54
- throw new ArgumentNullException ( nameof ( key ) ) ;
54
+ throw new ArgumentNullException ( nameof ( name ) ) ;
55
55
}
56
56
57
- return _localizer [ key , arguments ] ;
57
+ return ToHtmlString ( _localizer [ name ] , arguments ) ;
58
58
}
59
59
}
60
60
61
- /// <summary>
62
- /// Creates a new <see cref="IHtmlLocalizer"/> for a specific <see cref="CultureInfo"/>.
63
- /// </summary>
64
- /// <param name="culture">The <see cref="CultureInfo"/> to use.</param>
65
- /// <returns>A culture-specific <see cref="IHtmlLocalizer"/>.</returns>
66
- public virtual IHtmlLocalizer WithCulture ( CultureInfo culture )
67
- {
68
- if ( culture == null )
69
- {
70
- throw new ArgumentNullException ( nameof ( culture ) ) ;
71
- }
72
-
73
- return new HtmlLocalizer ( _localizer . WithCulture ( culture ) ) ;
74
- }
75
-
76
- /// <summary>
77
- /// Creates a new <see cref="IStringLocalizer"/> for a specific <see cref="CultureInfo"/>.
78
- /// </summary>
79
- /// <param name="culture">The <see cref="CultureInfo"/> to use.</param>
80
- /// <returns>A culture-specific <see cref="IStringLocalizer"/>.</returns>
81
- IStringLocalizer IStringLocalizer . WithCulture ( CultureInfo culture )
82
- {
83
- if ( culture == null )
84
- {
85
- throw new ArgumentNullException ( nameof ( culture ) ) ;
86
- }
87
-
88
- return new HtmlLocalizer ( _localizer . WithCulture ( culture ) ) ;
89
- }
90
-
91
61
/// <inheritdoc />
92
- public virtual LocalizedString GetString ( string key )
62
+ public virtual LocalizedString GetString ( string name )
93
63
{
94
- if ( key == null )
64
+ if ( name == null )
95
65
{
96
- throw new ArgumentNullException ( nameof ( key ) ) ;
66
+ throw new ArgumentNullException ( nameof ( name ) ) ;
97
67
}
98
68
99
- return _localizer . GetString ( key ) ;
69
+ return _localizer [ name ] ;
100
70
}
101
71
102
72
/// <inheritdoc />
103
- public virtual LocalizedString GetString ( string key , params object [ ] arguments )
73
+ public virtual LocalizedString GetString ( string name , params object [ ] arguments )
104
74
{
105
- if ( key == null )
75
+ if ( name == null )
106
76
{
107
- throw new ArgumentNullException ( nameof ( key ) ) ;
77
+ throw new ArgumentNullException ( nameof ( name ) ) ;
108
78
}
109
79
110
- return _localizer . GetString ( key , arguments ) ;
80
+ return _localizer [ name , arguments ] ;
111
81
}
112
82
113
83
/// <inheritdoc />
114
- public virtual IEnumerable < LocalizedString > GetAllStrings ( bool includeAncestorCultures ) =>
115
- _localizer . GetAllStrings ( includeAncestorCultures ) ;
84
+ public virtual IEnumerable < LocalizedString > GetAllStrings ( bool includeParentCultures ) =>
85
+ _localizer . GetAllStrings ( includeParentCultures ) ;
116
86
117
87
/// <inheritdoc />
118
- public virtual LocalizedHtmlString Html ( string key )
119
- {
120
- if ( key == null )
121
- {
122
- throw new ArgumentNullException ( nameof ( key ) ) ;
123
- }
124
-
125
- return ToHtmlString ( _localizer . GetString ( key ) ) ;
126
- }
127
-
128
- /// <inheritdoc />
129
- public virtual LocalizedHtmlString Html ( string key , params object [ ] arguments )
88
+ public virtual IHtmlLocalizer WithCulture ( CultureInfo culture )
130
89
{
131
- if ( key == null )
90
+ if ( culture == null )
132
91
{
133
- throw new ArgumentNullException ( nameof ( key ) ) ;
92
+ throw new ArgumentNullException ( nameof ( culture ) ) ;
134
93
}
135
94
136
- return ToHtmlString ( _localizer . GetString ( key ) , arguments ) ;
95
+ return new HtmlLocalizer ( _localizer . WithCulture ( culture ) ) ;
137
96
}
138
97
139
98
/// <summary>
0 commit comments