-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5094 from zyhfish/task/set-fa-ir-culture
Fix #5054: resolve the issue in fa-IR language.
- Loading branch information
Showing
3 changed files
with
127 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
42 changes: 42 additions & 0 deletions
42
Oqtane.Server/Infrastructure/Localization/RightToLeftCulture.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,42 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Reflection; | ||
|
||
namespace Oqtane.Infrastructure | ||
{ | ||
public class RightToLeftCulture | ||
{ | ||
public static CultureInfo ResolveFormat(CultureInfo cultureInfo) | ||
{ | ||
SetNumberFormatInfo(cultureInfo.NumberFormat); | ||
SetCalenar(cultureInfo); | ||
|
||
return cultureInfo; | ||
} | ||
|
||
private static void SetCalenar(CultureInfo cultureInfo) | ||
{ | ||
var calendar = new RightToLeftCultureCalendar(); | ||
|
||
var fieldInfo = cultureInfo.GetType().GetField("_calendar", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (fieldInfo != null) | ||
{ | ||
fieldInfo.SetValue(cultureInfo, calendar); | ||
} | ||
|
||
var info = cultureInfo.DateTimeFormat.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (info != null) | ||
{ | ||
info.SetValue(cultureInfo.DateTimeFormat, calendar); | ||
} | ||
} | ||
|
||
public static void SetNumberFormatInfo(NumberFormatInfo persianNumberFormatInfo) | ||
{ | ||
persianNumberFormatInfo.NumberDecimalSeparator = "."; | ||
persianNumberFormatInfo.DigitSubstitution = DigitShapes.NativeNational; | ||
persianNumberFormatInfo.NumberNegativePattern = 0; | ||
persianNumberFormatInfo.NegativeSign = "-"; | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
Oqtane.Server/Infrastructure/Localization/RightToLeftCultureCalendar.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,77 @@ | ||
using System; | ||
|
||
namespace Oqtane.Infrastructure | ||
{ | ||
public class RightToLeftCultureCalendar : System.Globalization.PersianCalendar | ||
{ | ||
public override int GetYear(DateTime time) | ||
{ | ||
try | ||
{ | ||
return base.GetYear(time); | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
|
||
return time.Year; | ||
} | ||
|
||
public override int GetMonth(DateTime time) | ||
{ | ||
try | ||
{ | ||
return base.GetMonth(time); | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
|
||
return time.Month; | ||
} | ||
|
||
public override int GetDayOfMonth(DateTime time) | ||
{ | ||
try | ||
{ | ||
return base.GetDayOfMonth(time); | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
|
||
return time.Day; | ||
} | ||
|
||
public override int GetDayOfYear(DateTime time) | ||
{ | ||
try | ||
{ | ||
return base.GetDayOfYear(time); | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
|
||
return time.DayOfYear; | ||
} | ||
|
||
public override DayOfWeek GetDayOfWeek(DateTime time) | ||
{ | ||
try | ||
{ | ||
return base.GetDayOfWeek(time); | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
|
||
return time.DayOfWeek; | ||
} | ||
} | ||
} |