diff --git a/SambatWidget.Core/BaseCalendarRenderer.cs b/SambatWidget.Core/BaseCalendarRenderer.cs index ac8f875..f7c0727 100644 --- a/SambatWidget.Core/BaseCalendarRenderer.cs +++ b/SambatWidget.Core/BaseCalendarRenderer.cs @@ -2,7 +2,7 @@ using SambatWidget.Core.Models; using System; using System.Collections.Generic; -using System.Linq; +using System.Reflection; namespace SambatWidget.Core { @@ -75,6 +75,14 @@ public string GetWeekDayName() } return DateTime.Now.DayOfWeek.ToString(); } + public string GetWeekDayNameNP() + { + if (!IsToday()) + { + return GetNepaliWeekDayName(GetThisMonthNepaliStartDate().DayOfWeek); + } + return GetNepaliWeekDayName(_carouselNepDate.DayOfWeek); + } public string GetShortWeekDayName() { if (!IsToday()) @@ -91,7 +99,15 @@ public string GetFormattedNepaliDate() { return $"{_carouselNepDate.MonthName} 1, {_carouselNepDate.Year}"; } - return $"{_carouselNepDate.MonthName} {_carouselNepDate.Day}, {_carouselNepDate.Year}"; + return _carouselNepDate.ToLongDateString(); + } + public string GetFormattedNepaliDateNP() + { + if (!IsToday()) + { + return new NepaliDate(_carouselNepDate.Year, _carouselNepDate.Month, 1).ToLongDateUnicodeString(); + } + return _carouselNepDate.ToLongDateUnicodeString(); } private List Populate() { @@ -155,5 +171,17 @@ public string GetYearMonthKey(int date) { return $"{_carouselNepDate.Year}-{_carouselNepDate.Month}-{date}"; } + private string GetNepaliWeekDayName(DayOfWeek dayOfWeek) => + dayOfWeek switch + { + DayOfWeek.Sunday => "आइतबार", + DayOfWeek.Monday => "सोमबार", + DayOfWeek.Tuesday => "मंगलबार", + DayOfWeek.Wednesday => "बुधबार", + DayOfWeek.Thursday => "बिहिबार", + DayOfWeek.Friday => "शुक्रबार", + DayOfWeek.Saturday => "शनिबार", + _ => string.Empty, + }; } } diff --git a/SambatWidget.Core/ICalendarRenderer.cs b/SambatWidget.Core/ICalendarRenderer.cs index 7668e06..c87bf46 100644 --- a/SambatWidget.Core/ICalendarRenderer.cs +++ b/SambatWidget.Core/ICalendarRenderer.cs @@ -1,4 +1,5 @@ using SambatWidget.Core.Models; +using System; using System.Collections.Generic; namespace SambatWidget.Core @@ -11,11 +12,13 @@ public interface ICalendarRenderer string GetConsecutiveEnglishYearsPair(); string GetConsecutiveEnglishMonthsPair(); string GetWeekDayName(); + string GetWeekDayNameNP(); string GetShortWeekDayName(); string GetMonthName(); int? GetRemainingDays(); string GetFormattedEnglishDate(); string GetFormattedNepaliDate(); + string GetFormattedNepaliDateNP(); bool IsToday(); string GetYearMonthKey(int date); } diff --git a/SambatWidget.Core/SambatWidget.Core.csproj b/SambatWidget.Core/SambatWidget.Core.csproj index 608021f..1f262e9 100644 --- a/SambatWidget.Core/SambatWidget.Core.csproj +++ b/SambatWidget.Core/SambatWidget.Core.csproj @@ -2,6 +2,7 @@ netstandard2.0 + 8.0 diff --git a/SambatWidget.UI/App.xaml b/SambatWidget.UI/App.xaml index 937031c..45b82a4 100644 --- a/SambatWidget.UI/App.xaml +++ b/SambatWidget.UI/App.xaml @@ -2,6 +2,7 @@ x:Class="SambatWidget.UI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:converters="clr-namespace:SambatWidget.UI.Converters" xmlns:local="clr-namespace:SambatWidget.UI" StartupUri="MainWindow.xaml"> @@ -52,6 +53,7 @@ + diff --git a/SambatWidget.UI/Controls/WidgetCalendarControl.xaml b/SambatWidget.UI/Controls/WidgetCalendarControl.xaml index 1c6a218..8f2021d 100644 --- a/SambatWidget.UI/Controls/WidgetCalendarControl.xaml +++ b/SambatWidget.UI/Controls/WidgetCalendarControl.xaml @@ -11,12 +11,6 @@ d:DesignWidth="800" mc:Ignorable="d"> - - - @@ -35,37 +29,37 @@ Grid.Column="0" HorizontalAlignment="Center" Style="{StaticResource text-sm}" - Text="Sun" /> + Text="{Binding WidgetCalendarViewModel.Sunday}" /> + Text="{Binding WidgetCalendarViewModel.Monday}" /> + Text="{Binding WidgetCalendarViewModel.Tuesday}" /> + Text="{Binding WidgetCalendarViewModel.Wednesday}" /> + Text="{Binding WidgetCalendarViewModel.Thursday}" /> + Text="{Binding WidgetCalendarViewModel.Friday}" /> + Text="{Binding WidgetCalendarViewModel.Saturday}" /> @@ -84,7 +78,7 @@ Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.HandleCellClickCommand}" CommandParameter="{Binding .}" Style="{StaticResource CalendarCellStyle}"> - + diff --git a/SambatWidget.UI/Controls/WidgetCalendarEventPopup.xaml b/SambatWidget.UI/Controls/WidgetCalendarEventPopup.xaml index ea2c56b..720e6db 100644 --- a/SambatWidget.UI/Controls/WidgetCalendarEventPopup.xaml +++ b/SambatWidget.UI/Controls/WidgetCalendarEventPopup.xaml @@ -28,7 +28,7 @@ + Text="{Binding EventInfo.Date, Converter={StaticResource EnglishToNepaliNumberConverter}}" /> (); + int numDigits = (int)Math.Floor(Math.Log10(number) + 1); + for (int i = numDigits - 1; i >= 0; i--) + { + int divisor = (int)Math.Pow(10, i); + int digit = (number / divisor) % 10; + result.Add(_digits[digit]); + } + return string.Join("", result); + } + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (App.Setting.IsNepali) + { + return ConvertToNepali((int)value); + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/SambatWidget.UI/Models/SettingModel.cs b/SambatWidget.UI/Models/SettingModel.cs index 916d2de..649e8f2 100644 --- a/SambatWidget.UI/Models/SettingModel.cs +++ b/SambatWidget.UI/Models/SettingModel.cs @@ -16,6 +16,7 @@ public class SettingModel public bool AllowGlobalPosition { get; set; } = true; public string Theme { get; set; } = "LightTheme"; public Point Position { get; set; } + public bool IsNepali { get; set; } public virtual SettingModel Save(Action action = null) { action?.Invoke(this); diff --git a/SambatWidget.UI/Resources/WidgetContextMenus.xaml b/SambatWidget.UI/Resources/WidgetContextMenus.xaml index e132f54..c3f25ba 100644 --- a/SambatWidget.UI/Resources/WidgetContextMenus.xaml +++ b/SambatWidget.UI/Resources/WidgetContextMenus.xaml @@ -23,6 +23,11 @@ CommandParameter="{Binding WidgetContextMenuViewModel.LongUnicodeFormat}" Header="{Binding WidgetContextMenuViewModel.LongUnicodeFormat}" /> + - - all - @@ -41,10 +38,6 @@ - - - - PreserveNewest diff --git a/SambatWidget.UI/ViewModels/WidgetCalendarViewModel.cs b/SambatWidget.UI/ViewModels/WidgetCalendarViewModel.cs index c2a92ac..a121988 100644 --- a/SambatWidget.UI/ViewModels/WidgetCalendarViewModel.cs +++ b/SambatWidget.UI/ViewModels/WidgetCalendarViewModel.cs @@ -1,10 +1,11 @@ -using SambatWidget.Core; +using CommunityToolkit.Mvvm.ComponentModel; +using SambatWidget.Core; using SambatWidget.Core.Models; using SambatWidget.UI.Helpers; namespace SambatWidget.UI.ViewModels { - public partial class WidgetCalendarViewModel + public partial class WidgetCalendarViewModel : ObservableObject { private readonly ICalendarRenderer _calendarRenderer; public WpfObservableRangeCollection CalendarCells { get; } @@ -14,10 +15,56 @@ public WidgetCalendarViewModel(ICalendarRenderer renderer) CalendarCells = new WpfObservableRangeCollection(); Init(); } + [ObservableProperty] + string sunday = "Sun"; + + [ObservableProperty] + string monday = "Mon"; + + [ObservableProperty] + string tuesday = "Tue"; + + [ObservableProperty] + string wednesday = "Wed"; + + [ObservableProperty] + string thursday = "Thu"; + + [ObservableProperty] + string friday = "Fri"; + + [ObservableProperty] + string saturday = "Sat"; public void Init() { + SetDynamicWeekdayNamesForHeader(); Render(() => CalendarCells.AddRange(_calendarRenderer.RenderToday())); } + + private void SetDynamicWeekdayNamesForHeader() + { + if (App.Setting.IsNepali) + { + Sunday = "आइ"; + Monday = "सोम"; + Tuesday = "मंगल"; + Wednesday = "बुध"; + Thursday = "बिहि"; + Friday = "शुक्र"; + Saturday = "शनि"; + } + else + { + Sunday = "Sun"; + Monday = "Mon"; + Tuesday = "Tue"; + Wednesday = "Wed"; + Thursday = "Thu"; + Friday = "Fri"; + Saturday = "Sat"; + } + } + public void RenderNext() { Render(() => CalendarCells.AddRange(_calendarRenderer.RenderNext())); @@ -26,6 +73,11 @@ public void RenderPrevious() { Render(() => CalendarCells.AddRange(_calendarRenderer.RenderPrevious())); } + public void ReRender() + { + CalendarCells.Clear(); + Init(); + } private void Render(Action renderAction) { CalendarCells.Clear(); diff --git a/SambatWidget.UI/ViewModels/WidgetHeaderViewModel.cs b/SambatWidget.UI/ViewModels/WidgetHeaderViewModel.cs index 8fedf5d..cf591af 100644 --- a/SambatWidget.UI/ViewModels/WidgetHeaderViewModel.cs +++ b/SambatWidget.UI/ViewModels/WidgetHeaderViewModel.cs @@ -21,18 +21,35 @@ public WidgetHeaderViewModel(ICalendarRenderer renderer) string timeZone; public void InitHeader() { - //use the abbreviated day of week name to reduce the space when timezone is enabled - Header = App.Setting.ShowTimeZone - ? _calendarRenderer.GetShortWeekDayName() - : _calendarRenderer.GetWeekDayName(); - - string engHeader = _calendarRenderer.GetConsecutiveEnglishMonthsPair(); - if (!App.Setting.IsExpanded) + SetHeader(); + InitTimeZone(); + SetSubHeader(); + } + private void SetHeader() + { + if (App.Setting.IsNepali) { - engHeader = _calendarRenderer.GetFormattedEnglishDate(); + Header = _calendarRenderer.GetWeekDayNameNP(); } - SubHeader = $"{_calendarRenderer.GetFormattedNepaliDate()} | {engHeader}"; - InitTimeZone(); + else + { + // Use the abbreviated day of the week name when the timezone is enabled + Header = App.Setting.ShowTimeZone + ? _calendarRenderer.GetShortWeekDayName() + : _calendarRenderer.GetWeekDayName(); + } + } + private void SetSubHeader() + { + // Get the English header, conditionally formatting based on expanded setting + string engHeader = App.Setting.IsExpanded + ? _calendarRenderer.GetConsecutiveEnglishMonthsPair() + : _calendarRenderer.GetFormattedEnglishDate(); + + // Set subheader with Nepali and English dates + SubHeader = App.Setting.IsNepali + ? $"{_calendarRenderer.GetFormattedNepaliDateNP()} | {engHeader}" + : $"{_calendarRenderer.GetFormattedNepaliDate()} | {engHeader}"; } public void InitTimeZone() { diff --git a/SambatWidget.UI/ViewModels/WidgetViewModel.cs b/SambatWidget.UI/ViewModels/WidgetViewModel.cs index 74ded49..ae1d2cc 100644 --- a/SambatWidget.UI/ViewModels/WidgetViewModel.cs +++ b/SambatWidget.UI/ViewModels/WidgetViewModel.cs @@ -18,6 +18,8 @@ public WidgetViewModel() WidgetCalendarViewModel = new WidgetCalendarViewModel(_calendarRenderer); WidgetContextMenuViewModel = new WidgetContextMenuViewModel(); } + [ObservableProperty] + bool isNepali = App.Setting.IsNepali; [ObservableProperty] bool isExpanded = App.Setting.IsExpanded; @@ -107,6 +109,13 @@ private void HideEventPopup() EventPopupVisible = false; } } + [RelayCommand] + private void ToggleNepaliLang() + { + App.Setting.Save(x => x.IsNepali = IsNepali); + WidgetCalendarViewModel.ReRender(); + WidgetHeaderViewModel.InitHeader(); + } private void DecideWhenToTransparent() { if (App.Setting.AllowTransparency)