Skip to content

Commit 8bfbe96

Browse files
authored
Merge pull request #158 from ite-klass/ngettext
Replace NGettext dependency
2 parents b455bb2 + 21e5875 commit 8bfbe96

File tree

8 files changed

+60
-18
lines changed

8 files changed

+60
-18
lines changed

src/FubarDev.FtpServer.Abstractions/Features/ILocalizationFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using System.Globalization;
66

7-
using NGettext;
7+
using FubarDev.FtpServer.Localization;
88

99
namespace FubarDev.FtpServer.Features
1010
{
@@ -21,6 +21,6 @@ public interface ILocalizationFeature
2121
/// <summary>
2222
/// Gets or sets the catalog to be used by the default FTP server implementation.
2323
/// </summary>
24-
ICatalog Catalog { get; set; }
24+
ILocalizationCatalog Catalog { get; set; }
2525
}
2626
}

src/FubarDev.FtpServer.Abstractions/Features/Impl/LocalizationFeature.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
using FubarDev.FtpServer.Localization;
88

9-
using NGettext;
10-
119
namespace FubarDev.FtpServer.Features.Impl
1210
{
1311
/// <summary>
@@ -29,6 +27,6 @@ public LocalizationFeature(IFtpCatalogLoader catalogLoader)
2927
public CultureInfo Language { get; set; }
3028

3129
/// <inheritdoc />
32-
public ICatalog Catalog { get; set; }
30+
public ILocalizationCatalog Catalog { get; set; }
3331
}
3432
}

src/FubarDev.FtpServer.Abstractions/FtpConnectionData.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
using Microsoft.AspNetCore.Http.Features;
2424

25-
using NGettext;
26-
2725
namespace FubarDev.FtpServer
2826
{
2927
/// <summary>
@@ -144,7 +142,7 @@ public CultureInfo Language
144142

145143
/// <inheritdoc />
146144
[Obsolete("Query the information using the ILocalizationFeature instead.")]
147-
public ICatalog Catalog
145+
public ILocalizationCatalog Catalog
148146
{
149147
get => _featureCollection.Get<ILocalizationFeature>().Catalog;
150148
set => _featureCollection.Get<ILocalizationFeature>().Catalog = value;

src/FubarDev.FtpServer.Abstractions/FubarDev.FtpServer.Abstractions.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
1212
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
1313
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
14-
<PackageReference Include="NGettext" Version="0.6.7" />
1514
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
1615
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />
1716
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// <copyright file="EmptyLocalizationCatalog.cs" company="iT Engineering - Software Innovations">
2+
// Copyright (c) Jan Klass. All rights reserved.
3+
// </copyright>
4+
5+
using System;
6+
using System.Globalization;
7+
8+
namespace FubarDev.FtpServer.Localization
9+
{
10+
/// <summary>A localization catalog that returns text as-is.</summary>
11+
/// <remarks>
12+
/// <para>The texts in-code are written in English, so the effectively serves as an English catalog by returning texts as-is.</para>
13+
/// <para>The culture formatting for values still applies though.</para>
14+
/// </remarks>
15+
public class EmptyLocalizationCatalog : ILocalizationCatalog
16+
{
17+
public EmptyLocalizationCatalog(CultureInfo cultureInfo)
18+
{
19+
CultureInfo = cultureInfo ?? throw new ArgumentNullException(nameof(cultureInfo));
20+
FormatProvider = cultureInfo;
21+
}
22+
23+
public CultureInfo CultureInfo { get; }
24+
25+
public IFormatProvider FormatProvider { get; }
26+
27+
public virtual string GetString(string text) => text;
28+
29+
public virtual string GetString(string text, params object[] args) => string.Format(FormatProvider, text, args);
30+
}
31+
}

src/FubarDev.FtpServer.Abstractions/Localization/IFtpCatalogLoader.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99

10-
using NGettext;
11-
1210
namespace FubarDev.FtpServer.Localization
1311
{
1412
/// <summary>
@@ -19,7 +17,7 @@ public interface IFtpCatalogLoader
1917
/// <summary>
2018
/// Gets the catalog for the <see cref="DefaultLanguage"/>.
2119
/// </summary>
22-
ICatalog DefaultCatalog { get; }
20+
ILocalizationCatalog DefaultCatalog { get; }
2321

2422
/// <summary>
2523
/// Gets the default language.
@@ -38,6 +36,6 @@ public interface IFtpCatalogLoader
3836
/// <param name="language">The language to load the catalog for.</param>
3937
/// <param name="cancellationToken">The cancellation token.</param>
4038
/// <returns>The loaded catalog.</returns>
41-
Task<ICatalog> LoadAsync(CultureInfo language, CancellationToken cancellationToken = default);
39+
Task<ILocalizationCatalog> LoadAsync(CultureInfo language, CancellationToken cancellationToken = default);
4240
}
4341
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// <copyright file="ILocalizationCatalog.cs" company="iT Engineering - Software Innovations">
2+
// Copyright (c) Jan Klass. All rights reserved.
3+
// </copyright>
4+
5+
namespace FubarDev.FtpServer.Localization
6+
{
7+
public interface ILocalizationCatalog
8+
{
9+
/// <summary>Translate <paramref name="text"/>.</summary>
10+
/// <param name="text">The text to be translated.</param>
11+
/// <returns>The translated text.</returns>
12+
string GetString(string text);
13+
14+
/// <summary>Translate <paramref name="text"/> with format values <paramref name="args"/>.</summary>
15+
/// <param name="text">The text to be translated.</param>
16+
/// <param name="args">The format arguments.</param>
17+
/// <returns>The translated text.</returns>
18+
string GetString(string text, params object[] args);
19+
}
20+
}

src/FubarDev.FtpServer/Localization/DefaultFtpCatalogLoader.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99

10-
using NGettext;
11-
1210
namespace FubarDev.FtpServer.Localization
1311
{
1412
/// <summary>
@@ -19,7 +17,7 @@ public class DefaultFtpCatalogLoader : IFtpCatalogLoader
1917
private static readonly CultureInfo _defaultLanguage = new CultureInfo("en");
2018

2119
/// <inheritdoc />
22-
public ICatalog DefaultCatalog { get; } = new Catalog(_defaultLanguage);
20+
public ILocalizationCatalog DefaultCatalog { get; } = new EmptyLocalizationCatalog(_defaultLanguage);
2321

2422
/// <inheritdoc />
2523
public CultureInfo DefaultLanguage { get; } = _defaultLanguage;
@@ -34,9 +32,9 @@ public IReadOnlyCollection<string> GetSupportedLanguages()
3432
}
3533

3634
/// <inheritdoc />
37-
public Task<ICatalog> LoadAsync(CultureInfo language, CancellationToken cancellationToken = default)
35+
public Task<ILocalizationCatalog> LoadAsync(CultureInfo language, CancellationToken cancellationToken = default)
3836
{
39-
return Task.FromResult<ICatalog>(new Catalog(language));
37+
return Task.FromResult<ILocalizationCatalog>(new EmptyLocalizationCatalog(language));
4038
}
4139
}
4240
}

0 commit comments

Comments
 (0)