From 382ce6481842224317b17469dc4287134e32ca55 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Tue, 6 Sep 2022 10:12:54 +0300 Subject: [PATCH] Extract GetLanguageDirection() and IsRightToLeft() to CultureInfoExtensions (#12315) --- .../Extensions/CultureInfoExtensions.cs | 23 +++++++++++ .../LanguageDirection.cs | 41 +++++-------------- 2 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/CultureInfoExtensions.cs diff --git a/src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/CultureInfoExtensions.cs b/src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/CultureInfoExtensions.cs new file mode 100644 index 00000000000..92ffee6d3f8 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Localization.Abstractions/Extensions/CultureInfoExtensions.cs @@ -0,0 +1,23 @@ +using System.Globalization; + +namespace OrchardCore.Localization; + +/// +/// Provides an extension methods for to deal with language direction. +/// +public static class CultureInfoExtensions +{ + /// + /// Gets the language direction for a given culture. + /// + /// The . + public static string GetLanguageDirection(this CultureInfo culture) => culture.IsRightToLeft() + ? LanguageDirection.RTL + : LanguageDirection.LTR; + + /// + /// Gets whether the culture is RTL or not. + /// + /// The culture. + public static bool IsRightToLeft(this CultureInfo culture) => culture.TextInfo.IsRightToLeft; +} diff --git a/src/OrchardCore/OrchardCore.Localization.Abstractions/LanguageDirection.cs b/src/OrchardCore/OrchardCore.Localization.Abstractions/LanguageDirection.cs index 45bb2a79bcd..29c84cb2fc2 100644 --- a/src/OrchardCore/OrchardCore.Localization.Abstractions/LanguageDirection.cs +++ b/src/OrchardCore/OrchardCore.Localization.Abstractions/LanguageDirection.cs @@ -1,36 +1,17 @@ -using System.Globalization; +namespace OrchardCore.Localization; -namespace OrchardCore.Localization +/// +/// Provides a language directions. +/// +public static class LanguageDirection { /// - /// Provides a language directions and helper methods that extend . + /// Defines left to right direction. /// - public static class LanguageDirection - { - /// - /// Defines left to right direction. - /// - public static readonly string LTR = "ltr"; + public static readonly string LTR = "ltr"; - /// - /// Defines right to left direction. - /// - public static readonly string RTL = "rtl"; - - /// - /// Gets the language direction for a given culture. - /// - /// The . - /// - public static string GetLanguageDirection(this CultureInfo culture) - => culture.TextInfo.IsRightToLeft ? RTL : LTR; - - /// - /// Gets whether the culture is RTL or not. - /// - /// The culture. - /// - public static bool IsRightToLeft(this CultureInfo culture) - => culture.TextInfo.IsRightToLeft; - } + /// + /// Defines right to left direction. + /// + public static readonly string RTL = "rtl"; }