-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract GetLanguageDirection() and IsRightToLeft() to CultureInfoExte…
…nsions (#12315)
- Loading branch information
Showing
2 changed files
with
34 additions
and
30 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/CultureInfoExtensions.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,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; | ||
} |
41 changes: 11 additions & 30 deletions
41
src/OrchardCore/OrchardCore.Localization.Abstractions/LanguageDirection.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 |
---|---|---|
@@ -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"; | ||
} |