Skip to content

Commit

Permalink
Add obsoelte
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed May 19, 2024
1 parent 697c636 commit 62db552
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Lepo.i18n/Translator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and Lepo.i18n Contributors.
// All Rights Reserved.

namespace Lepo.i18n;

/// <summary>
/// Provides functionality to translate strings. This class is obsolete and <see cref="LocalizationProvider"/> should be used instead.
/// </summary>
[Obsolete($"{nameof(Translator)} is obsolete, use {nameof(LocalizationProvider)} instead.")]
public static class Translator
{
/// <summary>
/// Translates a string to the current culture.
/// </summary>
/// <param name="value">The string to translate.</param>
/// <returns>The translated string if a translation exists, otherwise the original string.</returns>
[Obsolete("This method is obsolete and should not be used.")]
public static string String(string value)
{
if (value is null)
{
return string.Empty;
}

LocalizationSet? localizationSet = LocalizationProvider
.GetInstance()
?.Get(LocalizationProvider.GetInstance()?.GetCulture() ?? CultureInfo.CurrentUICulture);
;

if (localizationSet is null)
{
return value;
}

return localizationSet.Strings.FirstOrDefault(s => s.Key == value).Value ?? value;
}

/// <summary>
/// Prepares a string for translation. This method is obsolete and should not be used.
/// </summary>
/// <param name="value">The text or key to prepare.</param>
/// <param name="parameters">The parameters to use in the prepared string.</param>
/// <returns>Throws an exception indicating that this method is obsolete.</returns>
[Obsolete("This method is obsolete and should not be used.")]
public static string Prepare(string value, params object[] parameters)
{
throw new Exception("This method is obsolete and should not be used.");
}

/// <summary>
/// Translates a string to the correct plural form for the current culture. This method is obsolete and should not be used.
/// </summary>
/// <param name="single">The singular form of the string.</param>
/// <param name="plural">The plural form of the string.</param>
/// <param name="number">The number to determine the correct form.</param>
/// <returns>Throws an exception indicating that this method is obsolete.</returns>
[Obsolete("This method is obsolete and should not be used.")]
public static string Plural(string single, string plural, object number)
{
throw new Exception("This method is obsolete and should not be used.");
}
}
1 change: 1 addition & 0 deletions tests/Lepo.i18n.UnitTests/Yaml/FromYamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class FromYamlTests
public void FromYaml_ShouldProperlyAddLocalizations()
{
LocalizationBuilder builder = new();

_ = builder.FromYaml(
"Lepo.i18n.UnitTests.Resources.Translations.pl_PL.yaml",
new CultureInfo("pl-PL")
Expand Down

0 comments on commit 62db552

Please sign in to comment.