-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The FTP protocol supports translation of response texts (while FTP commands and codes never change). Support for text translations was implemented through ILocalizationFeature and the NGettext dependency and its ICatalog and Catalog types. The NGettext catalog attempts to load translation files - but by default fails as there are no translation files by default. This changeset drops the NGettext dependency in favor of implementing our own interface. The interface surface is reduced by defining only the methods we use. This is a *breaking change* (although with low impact). * Users who previously implemented and registered an ICatalog for custom text translation will have to instead implement ILocalizationCatalog. This is a trivial type reference replacement - the two methods we use are equal on both interfaces. * Users who made use of NGettext library magic translation file loading (I assume it may identify and load files if placed correctly) will need to implement a simple forwarding catalog type. References: * #144 #144 * RFC 2640 Internationalization of the File Transfer Protocol * https://github.com/VitaliiTsilnyk/NGettext
- Loading branch information
Showing
8 changed files
with
60 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/FubarDev.FtpServer.Abstractions/Localization/EmptyLocalizationCatalog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// <copyright file="EmptyLocalizationCatalog.cs" company="iT Engineering - Software Innovations"> | ||
// Copyright (c) Jan Klass. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Globalization; | ||
|
||
namespace FubarDev.FtpServer.Localization | ||
{ | ||
/// <summary>A localization catalog that returns text as-is.</summary> | ||
/// <remarks> | ||
/// <para>The texts in-code are written in English, so the effectively serves as an English catalog by returning texts as-is.</para> | ||
/// <para>The culture formatting for values still applies though.</para> | ||
/// </remarks> | ||
public class EmptyLocalizationCatalog : ILocalizationCatalog | ||
{ | ||
public EmptyLocalizationCatalog(CultureInfo cultureInfo) | ||
{ | ||
CultureInfo = cultureInfo ?? throw new ArgumentNullException(nameof(cultureInfo)); | ||
FormatProvider = cultureInfo; | ||
} | ||
|
||
public CultureInfo CultureInfo { get; } | ||
|
||
public IFormatProvider FormatProvider { get; } | ||
|
||
public virtual string GetString(string text) => text; | ||
|
||
public virtual string GetString(string text, params object[] args) => string.Format(FormatProvider, text, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/FubarDev.FtpServer.Abstractions/Localization/ILocalizationCatalog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// <copyright file="ILocalizationCatalog.cs" company="iT Engineering - Software Innovations"> | ||
// Copyright (c) Jan Klass. All rights reserved. | ||
// </copyright> | ||
|
||
namespace FubarDev.FtpServer.Localization | ||
{ | ||
public interface ILocalizationCatalog | ||
{ | ||
/// <summary>Translate <paramref name="text"/>.</summary> | ||
/// <param name="text">The text to be translated.</param> | ||
/// <returns>The translated text.</returns> | ||
string GetString(string text); | ||
|
||
/// <summary>Translate <paramref name="text"/> with format values <paramref name="args"/>.</summary> | ||
/// <param name="text">The text to be translated.</param> | ||
/// <param name="args">The format arguments.</param> | ||
/// <returns>The translated text.</returns> | ||
string GetString(string text, params object[] args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters