6
6
namespace Lepo . i18n . DependencyInjection ;
7
7
8
8
/// <summary>
9
- /// Provides functionality to localize strings .
9
+ /// Provides a provider-based implementation of the <see cref="IStringLocalizer"/> interface .
10
10
/// </summary>
11
- public class StaticStringLocalizer (
11
+ /// <remarks>
12
+ /// This class uses an <see cref="ILocalizationProvider"/> to retrieve localization sets,
13
+ /// and an <see cref="ILocalizationCultureManager"/> to manage the current culture.
14
+ /// </remarks>
15
+ public class ProviderBasedStringLocalizer (
12
16
ILocalizationProvider localizations ,
13
17
ILocalizationCultureManager cultureManager
14
18
) : IStringLocalizer
15
19
{
16
- /// <summary>
17
- /// Gets the localized string for the specified name.
18
- /// </summary>
19
- /// <param name="name">The name of the localized string.</param>
20
- /// <returns>The localized string.</returns>
20
+ /// <inheritdoc />
21
21
public LocalizedString this [ string name ] => this [ name , [ ] ] ;
22
22
23
- /// <summary>
24
- /// Gets the localized string for the specified name and format arguments.
25
- /// </summary>
26
- /// <param name="name">The name of the localized string.</param>
27
- /// <param name="arguments">The format arguments.</param>
28
- /// <returns>The localized string.</returns>
23
+ /// <inheritdoc />
29
24
public LocalizedString this [ string name , params object [ ] arguments ] =>
30
25
LocalizeString ( name , arguments ) ;
31
26
32
- /// <summary>
33
- /// Gets all the localized strings for the current culture.
34
- /// </summary>
35
- /// <param name="_">A boolean parameter (not used).</param>
36
- /// <returns>The localized strings.</returns>
27
+ /// <inheritdoc />
37
28
public IEnumerable < LocalizedString > GetAllStrings ( bool _ )
38
29
{
39
30
return localizations
40
31
. GetLocalizationSet ( cultureManager . GetCulture ( ) , default )
41
32
? . Strings . Select ( x => new LocalizedString ( x . Key , x . Value ?? x . Key ) ) ?? [ ] ;
42
33
}
43
34
35
+ /// <summary>
36
+ /// Fills placeholders in a string with the provided values.
37
+ /// </summary>
38
+ /// <param name="name">The string with placeholders.</param>
39
+ /// <param name="placeholders">The values to fill the placeholders with.</param>
40
+ /// <returns>The string with filled placeholders.</returns>
44
41
private LocalizedString LocalizeString ( string name , object [ ] placeholders )
45
42
{
46
43
return new LocalizedString (
@@ -52,6 +49,12 @@ private LocalizedString LocalizeString(string name, object[] placeholders)
52
49
) ;
53
50
}
54
51
52
+ /// <summary>
53
+ /// Fills placeholders in a string with the provided values.
54
+ /// </summary>
55
+ /// <param name="value">The string with placeholders.</param>
56
+ /// <param name="placeholders">The values to fill the placeholders with.</param>
57
+ /// <returns>The string with filled placeholders.</returns>
55
58
private static string FillPlaceholders ( string value , object [ ] placeholders )
56
59
{
57
60
for ( int i = 0 ; i < placeholders . Length ; i ++ )
0 commit comments