From: tarunkumarmahay1999 Date: Tue, 16 Jan 2024 07:22:48 +0000 (+0530) Subject: Adding multi language support X-Git-Tag: accepted/tizen/unified/20240118.114132^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a5ff4c7670d891808735d296611a258cccfba344;p=profile%2Fiot%2Fapps%2Fdotnet%2Ftaskbar.git Adding multi language support Change-Id: Ibc153463450c8e1f357020cc65cea42688c9cd80 Signed-off-by: tarunkumarmahay1999 --- diff --git a/TaskBar/Common/MultiResourceManager.cs b/TaskBar/Common/MultiResourceManager.cs new file mode 100644 index 0000000..746c72c --- /dev/null +++ b/TaskBar/Common/MultiResourceManager.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Globalization; +using System.Reflection; +using System.Resources; + +namespace TaskBar.Common +{ + public class MultiResourceManager : ResourceManager + { + public MultiResourceManager(string baseName, Assembly assembly) + : base(baseName, assembly) + { + } + + public override string GetString(string name) + { + return base.GetString(name) + ?? TextResources.LanguageResources.ResourceManager.GetString(name); + } + + public override string GetString(string name, CultureInfo culture) + { + return base.GetString(name, culture) + ?? TextResources.LanguageResources.ResourceManager.GetString(name, culture); + } + } +} diff --git a/TaskBar/Common/Resources.cs b/TaskBar/Common/Resources.cs index 46dbed7..6ee20eb 100644 --- a/TaskBar/Common/Resources.cs +++ b/TaskBar/Common/Resources.cs @@ -18,8 +18,19 @@ using Tizen.NUI; namespace TaskBar.Common { - class Resources + static class Resources { + public static class Text + { + public const string OpenApp = "IDS_OPEN"; + public const string UnpinApp = "IDS_UNPIN"; + public const string CloseApp = "IDS_CLOSE"; + public const string PinApp = "IDS_PIN"; + public const string ClearNotification = "IDS_CLEAR"; + public const string UninstallApp = "IDS_UNINSTALL"; + public const string AddApps = "IDS_ADD_APPS"; + } + public const string LogTag = "TaskBar"; public const string LightPlatformThemeId = "org.tizen.default-light-theme"; public const string DarkPlatformThemeId = "org.tizen.default-dark-theme"; diff --git a/TaskBar/Models/AppInfoModel.cs b/TaskBar/Models/AppInfoModel.cs index 9186ab2..dbaed87 100644 --- a/TaskBar/Models/AppInfoModel.cs +++ b/TaskBar/Models/AppInfoModel.cs @@ -21,6 +21,7 @@ using Tizen.Applications.NotificationEventListener; using Tizen.NUI.Binding; using TaskBar.Common; using TaskBar.Core; +using TaskBar.TextResources; namespace TaskBar.Models { @@ -124,22 +125,22 @@ namespace TaskBar.Models string itemText = (string)selectedItemText; switch (itemText) { - case "Open": + case Resources.Text.OpenApp: OnAppSelect(selectedItemText); break; - case "Close": + case Resources.Text.CloseApp: TaskBarAppsLauncher.CloseApplication(ApplicationId); break; - case "Pin to task bar": + case Resources.Text.PinApp: PinAppClicked?.Invoke(); break; - case "Unpin from task bar": + case Resources.Text.UnpinApp: UnpinAppClicked?.Invoke(); break; - case "Uninstall app": + case Resources.Text.UninstallApp: UninstallAppClicked?.Invoke(); break; - case "Clear notifications": + case Resources.Text.ClearNotification: DeleteAllNotifications(); break; default: @@ -163,7 +164,7 @@ namespace TaskBar.Models { List menuItems = new List { - "Open", IsPinned ? "Unpin from task bar" : "Pin to task bar", "Close", "Uninstall app" + Resources.Text.OpenApp, IsPinned ? Resources.Text.UnpinApp : Resources.Text.PinApp, Resources.Text.CloseApp, Resources.Text.UninstallApp }; MoreMenuItems = menuItems; } diff --git a/TaskBar/TaskBar.cs b/TaskBar/TaskBar.cs index ed6457c..56aed6c 100644 --- a/TaskBar/TaskBar.cs +++ b/TaskBar/TaskBar.cs @@ -20,6 +20,8 @@ using Tizen.NUI.WindowSystem.Shell; using TaskBar.Common; using TaskBar.Core; using TaskBar.Views; +using System.Globalization; +using System; namespace TaskBar { @@ -37,6 +39,7 @@ namespace TaskBar protected override void OnCreate() { base.OnCreate(); + SetupLanguage(); window = GetDefaultWindow(); List list = new List { @@ -62,6 +65,27 @@ namespace TaskBar window.OrientationChanged += OnOrientationChanged; } + private void SetupLanguage() + { + void SetLanguage() + { + try + { + string language = Tizen.System.SystemSettings.LocaleLanguage.Replace("_", "-"); + var culture = CultureInfo.CreateSpecificCulture(language); + CultureInfo.CurrentCulture = culture; + TextResources.LanguageResources.Culture = culture; + } + catch (Exception e) + { + Tizen.Log.Error(Resources.LogTag, "Setting Language failed" + e.Message); + } + } + MultilingualResourceManager = new MultiResourceManager("Taskbar.TextResources.LanguageResources", typeof(TextResources.LanguageResources).Assembly); + Tizen.System.SystemSettings.LocaleLanguageChanged += (s, e) => SetLanguage(); + SetLanguage(); + } + private void OnOrientationChanged(object sender, WindowOrientationChangedEventArgs e) { DeviceInfo.Instance.UpdateDeviceInfo(); diff --git a/TaskBar/TaskBar.csproj b/TaskBar/TaskBar.csproj index b025d51..ff8399b 100644 --- a/TaskBar/TaskBar.csproj +++ b/TaskBar/TaskBar.csproj @@ -22,4 +22,25 @@ + + + True + True + LanguageResources.resx + + + + + + PublicResXFileCodeGenerator + + + PublicResXFileCodeGenerator + + + PublicResXFileCodeGenerator + LanguageResources.Designer.cs + + + diff --git a/TaskBar/TextResources/LanguageResources.Designer.cs b/TaskBar/TextResources/LanguageResources.Designer.cs new file mode 100644 index 0000000..dcc22bb --- /dev/null +++ b/TaskBar/TextResources/LanguageResources.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TaskBar.TextResources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class LanguageResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal LanguageResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TaskBar.TextResources.LanguageResources", typeof(LanguageResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Add Apps. + /// + public static string IDS_ADD_APPS { + get { + return ResourceManager.GetString("IDS_ADD_APPS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Clear notifications. + /// + public static string IDS_CLEAR { + get { + return ResourceManager.GetString("IDS_CLEAR", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close. + /// + public static string IDS_CLOSE { + get { + return ResourceManager.GetString("IDS_CLOSE", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open. + /// + public static string IDS_OPEN { + get { + return ResourceManager.GetString("IDS_OPEN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Pin to taskbar. + /// + public static string IDS_PIN { + get { + return ResourceManager.GetString("IDS_PIN", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Uninstall app. + /// + public static string IDS_UNINSTALL { + get { + return ResourceManager.GetString("IDS_UNINSTALL", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unpin from taskbar. + /// + public static string IDS_UNPIN { + get { + return ResourceManager.GetString("IDS_UNPIN", resourceCulture); + } + } + } +} diff --git a/TaskBar/TextResources/LanguageResources.en-US.resx b/TaskBar/TextResources/LanguageResources.en-US.resx new file mode 100644 index 0000000..8c99d5a --- /dev/null +++ b/TaskBar/TextResources/LanguageResources.en-US.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Add Apps + + + Clear notifications + + + Close + + + Open + + + Pin to taskbar + + + Uninstall app + + + Unpin from taskbar + + \ No newline at end of file diff --git a/TaskBar/TextResources/LanguageResources.ko-KR.resx b/TaskBar/TextResources/LanguageResources.ko-KR.resx new file mode 100644 index 0000000..fd71972 --- /dev/null +++ b/TaskBar/TextResources/LanguageResources.ko-KR.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 앱 추가 + + + 알림 지우기 + + + 닫기 + + + 열기 + + + 작업표시줄에 추가 + + + 앱 삭제 + + + 작업표시줄에서 제거 + + \ No newline at end of file diff --git a/TaskBar/TextResources/LanguageResources.resx b/TaskBar/TextResources/LanguageResources.resx new file mode 100644 index 0000000..8c99d5a --- /dev/null +++ b/TaskBar/TextResources/LanguageResources.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Add Apps + + + Clear notifications + + + Close + + + Open + + + Pin to taskbar + + + Uninstall app + + + Unpin from taskbar + + \ No newline at end of file diff --git a/TaskBar/ViewModels/QuickAccessViewModel.cs b/TaskBar/ViewModels/QuickAccessViewModel.cs index 1175d89..683117b 100644 --- a/TaskBar/ViewModels/QuickAccessViewModel.cs +++ b/TaskBar/ViewModels/QuickAccessViewModel.cs @@ -22,6 +22,7 @@ using Tizen.Applications.NotificationEventListener; using Tizen.NUI; using TaskBar.Common; using TaskBar.Models; +using TaskBar.TextResources; namespace TaskBar.ViewModels { @@ -154,16 +155,16 @@ namespace TaskBar.ViewModels List moreMenuList = new List(); if (item.Key != "back") { - moreMenuList.Add("Open"); + moreMenuList.Add(Resources.Text.OpenApp); } if (item.Key == "notifications") { - moreMenuList.Add("Clear notifications"); - moreMenuList.Add("Close"); + moreMenuList.Add(Resources.Text.ClearNotification); + moreMenuList.Add(Resources.Text.CloseApp); } else if (item.Key == "apps" || item.Key == "settings") { - moreMenuList.Add("Close"); + moreMenuList.Add(Resources.Text.CloseApp); } appInfoModel.MoreMenuItems = moreMenuList; buttons.Add(appInfoModel); diff --git a/TaskBar/Views/AppItemView.cs b/TaskBar/Views/AppItemView.cs index f82fb5f..41691e7 100644 --- a/TaskBar/Views/AppItemView.cs +++ b/TaskBar/Views/AppItemView.cs @@ -22,6 +22,7 @@ using Tizen.NUI.BaseComponents; using Tizen.NUI.Binding; using Tizen.NUI.Components; using TaskBar.Common; +using TaskBar.TextResources; namespace TaskBar.Views { @@ -141,7 +142,7 @@ namespace TaskBar.Views Normal = Resources.NormalMenuItemTextColor, }; item.TextColorSelector = colors; - if (item.Text == "Uninstall app") + if (item.Text == Resources.Text.UninstallApp) { item.TextColor = Resources.UninstallMenuItemTextColor; } @@ -215,7 +216,7 @@ namespace TaskBar.Views { foreach (MenuItem item in moreMenu.Items as List) { - if (item.Text == "Close") + if (item.TranslatableText == Resources.Text.CloseApp) { item.IsEnabled = showIndicator; } @@ -273,13 +274,13 @@ namespace TaskBar.Views FontFamily = "BreezeSans", HorizontalAlignment = HorizontalAlignment.Begin, VerticalAlignment = VerticalAlignment.Center, - Text = menuItemName, + TranslatableText = menuItemName, }, IsSelectable = false, }; MenuItem item = new MenuItem(buttonStyle); - if (menuItemName == "Close") + if (menuItemName == Resources.Text.CloseApp) { item.IsEnabled = showIndicator; } @@ -298,7 +299,7 @@ namespace TaskBar.Views private void OnItemClicked(object sender, ClickedEventArgs e) { MenuItem item = sender as MenuItem; - string itemText = item.Text; + string itemText = item.TranslatableText; DisposeMenuItems(); DisposeMoreMenu(); MenuItemSelectCommand.Execute(itemText); diff --git a/TaskBar/Views/MainView.cs b/TaskBar/Views/MainView.cs index 52085ac..e9fd9ce 100644 --- a/TaskBar/Views/MainView.cs +++ b/TaskBar/Views/MainView.cs @@ -22,6 +22,7 @@ using Tizen.NUI.Components; using TaskBar.Common; using TaskBar.Core; using TaskBar.ViewModels; +using TaskBar.TextResources; namespace TaskBar.Views { @@ -219,7 +220,7 @@ namespace TaskBar.Views FontFamily = "BreezeSans", HorizontalAlignment = HorizontalAlignment.Begin, VerticalAlignment = VerticalAlignment.Center, - Text = "Add Apps", + TranslatableText = Resources.Text.AddApps, }, IsSelectable = false, }; diff --git a/packaging/org.tizen.taskbar-1.0.0.tpk b/packaging/org.tizen.taskbar-1.0.0.tpk index 86c9d51..732aa55 100644 Binary files a/packaging/org.tizen.taskbar-1.0.0.tpk and b/packaging/org.tizen.taskbar-1.0.0.tpk differ