Skip to content

Commit

Permalink
Extract GetLanguageDirection() and IsRightToLeft() to CultureInfoExte…
Browse files Browse the repository at this point in the history
…nsions (#12315)
  • Loading branch information
hishamco authored Sep 6, 2022
1 parent 0bb23e7 commit 382ce64
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Globalization;

namespace OrchardCore.Localization;

/// <summary>
/// Provides an extension methods for <see cref="CultureInfo"/> to deal with language direction.
/// </summary>
public static class CultureInfoExtensions
{
/// <summary>
/// Gets the language direction for a given culture.
/// </summary>
/// <param name="culture">The <see cref="CultureInfo"/>.</param>
public static string GetLanguageDirection(this CultureInfo culture) => culture.IsRightToLeft()
? LanguageDirection.RTL
: LanguageDirection.LTR;

/// <summary>
/// Gets whether the culture is RTL or not.
/// </summary>
/// <param name="culture">The culture.</param>
public static bool IsRightToLeft(this CultureInfo culture) => culture.TextInfo.IsRightToLeft;
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
using System.Globalization;
namespace OrchardCore.Localization;

namespace OrchardCore.Localization
/// <summary>
/// Provides a language directions.
/// </summary>
public static class LanguageDirection
{
/// <summary>
/// Provides a language directions and helper methods that extend <see cref="CultureInfo"/>.
/// Defines left to right direction.
/// </summary>
public static class LanguageDirection
{
/// <summary>
/// Defines left to right direction.
/// </summary>
public static readonly string LTR = "ltr";
public static readonly string LTR = "ltr";

/// <summary>
/// Defines right to left direction.
/// </summary>
public static readonly string RTL = "rtl";

/// <summary>
/// Gets the language direction for a given culture.
/// </summary>
/// <param name="culture">The <see cref="CultureInfo"/>.</param>
/// <returns></returns>
public static string GetLanguageDirection(this CultureInfo culture)
=> culture.TextInfo.IsRightToLeft ? RTL : LTR;

/// <summary>
/// Gets whether the culture is RTL or not.
/// </summary>
/// <param name="culture">The culture.</param>
/// <returns></returns>
public static bool IsRightToLeft(this CultureInfo culture)
=> culture.TextInfo.IsRightToLeft;
}
/// <summary>
/// Defines right to left direction.
/// </summary>
public static readonly string RTL = "rtl";
}

0 comments on commit 382ce64

Please sign in to comment.