-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
697c636
commit 62db552
Showing
2 changed files
with
65 additions
and
0 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
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."); | ||
} | ||
} |
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