Skip to content

Commit 86f8da3

Browse files
authored
Use GetLocalized string extension from Windows Community Toolkit (#2180)
1 parent 381bb4c commit 86f8da3

34 files changed

+232
-215
lines changed

Files/App.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.AppCenter;
1111
using Microsoft.AppCenter.Analytics;
1212
using Microsoft.AppCenter.Crashes;
13+
using Microsoft.Toolkit.Uwp.Extensions;
1314
using Microsoft.Toolkit.Uwp.Helpers;
1415
using Microsoft.Toolkit.Uwp.Notifications;
1516
using Newtonsoft.Json;
@@ -443,7 +444,7 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
443444

444445
public static void SaveSessionTabs() // Enumerates through all tabs and gets the Path property and saves it to AppSettings.LastSessionPages
445446
{
446-
AppSettings.LastSessionPages = MainPage.AppInstances.DefaultIfEmpty().Select(tab => tab != null ? tab.Path ?? ResourceController.GetTranslation("NewTab") : ResourceController.GetTranslation("NewTab")).ToArray();
447+
AppSettings.LastSessionPages = MainPage.AppInstances.DefaultIfEmpty().Select(tab => tab != null ? tab.Path ?? "NewTab".GetLocalized() : "NewTab".GetLocalized()).ToArray();
447448
}
448449

449450
// Occurs when an exception is not handled on the UI thread.
@@ -468,11 +469,11 @@ private static void AppUnhandledException(Exception ex)
468469
{
469470
new AdaptiveText()
470471
{
471-
Text = ResourceController.GetTranslation("ExceptionNotificationHeader")
472+
Text = "ExceptionNotificationHeader".GetLocalized()
472473
},
473474
new AdaptiveText()
474475
{
475-
Text = ResourceController.GetTranslation("ExceptionNotificationBody")
476+
Text = "ExceptionNotificationBody".GetLocalized()
476477
}
477478
},
478479
AppLogoOverride = new ToastGenericAppLogo()
@@ -485,7 +486,7 @@ private static void AppUnhandledException(Exception ex)
485486
{
486487
Buttons =
487488
{
488-
new ToastButton(ResourceController.GetTranslation("ExceptionNotificationReportButton"), "report")
489+
new ToastButton("ExceptionNotificationReportButton".GetLocalized(), "report")
489490
{
490491
ActivationType = ToastActivationType.Foreground
491492
}

Files/BaseLayout.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Files.View_Models;
88
using Files.Views;
99
using Files.Views.Pages;
10+
using Microsoft.Toolkit.Uwp.Extensions;
1011
using Microsoft.Toolkit.Uwp.UI.Extensions;
1112
using Newtonsoft.Json;
1213
using System;
@@ -95,12 +96,12 @@ internal set
9596

9697
if (SelectedItems.Count == 1)
9798
{
98-
SelectedItemsPropertiesViewModel.SelectedItemsCountString = SelectedItems.Count.ToString() + " " + ResourceController.GetTranslation("ItemSelected/Text");
99+
SelectedItemsPropertiesViewModel.SelectedItemsCountString = SelectedItems.Count.ToString() + " " + "ItemSelected/Text".GetLocalized();
99100
SelectedItemsPropertiesViewModel.ItemSize = SelectedItem.FileSize;
100101
}
101102
else
102103
{
103-
SelectedItemsPropertiesViewModel.SelectedItemsCountString = SelectedItems.Count.ToString() + " " + ResourceController.GetTranslation("ItemsSelected/Text");
104+
SelectedItemsPropertiesViewModel.SelectedItemsCountString = SelectedItems.Count.ToString() + " " + "ItemsSelected/Text".GetLocalized();
104105

105106
if (SelectedItems.All(x => x.PrimaryItemAttribute == StorageItemTypes.File))
106107
{
@@ -295,7 +296,7 @@ private void LoadMenuFlyoutItem(IList<MenuFlyoutItemBase> MenuItemsList, IEnumer
295296
{
296297
var menuLayoutSubItem = new MenuFlyoutSubItem()
297298
{
298-
Text = ResourceController.GetTranslation("ContextMenuMoreItemsLabel"),
299+
Text = "ContextMenuMoreItemsLabel".GetLocalized(),
299300
Tag = ((Win32ContextMenuItem)null, menuHandle),
300301
Icon = new FontIcon()
301302
{
@@ -581,12 +582,12 @@ protected async void List_DragOver(object sender, DragEventArgs e)
581582
}
582583
else if (draggedItems.AreItemsInSameDrive(App.CurrentInstance.FilesystemViewModel.WorkingDirectory))
583584
{
584-
e.DragUIOverride.Caption = string.Format(ResourceController.GetTranslation("MoveToFolderCaptionText"), folderName);
585+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
585586
e.AcceptedOperation = DataPackageOperation.Move;
586587
}
587588
else
588589
{
589-
e.DragUIOverride.Caption = string.Format(ResourceController.GetTranslation("CopyToFolderCaptionText"), folderName);
590+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
590591
e.AcceptedOperation = DataPackageOperation.Copy;
591592
}
592593
}
@@ -685,12 +686,12 @@ protected async void Item_DragOver(object sender, DragEventArgs e)
685686
// Items from the same drive as this folder are dragged into this folder, so we move the items instead of copy
686687
else if (draggedItems.AreItemsInSameDrive(item.ItemPath))
687688
{
688-
e.DragUIOverride.Caption = string.Format(ResourceController.GetTranslation("MoveToFolderCaptionText"), item.ItemName);
689+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), item.ItemName);
689690
e.AcceptedOperation = DataPackageOperation.Move;
690691
}
691692
else
692693
{
693-
e.DragUIOverride.Caption = string.Format(ResourceController.GetTranslation("CopyToFolderCaptionText"), item.ItemName);
694+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), item.ItemName);
694695
e.AcceptedOperation = DataPackageOperation.Copy;
695696
}
696697
}

Files/Commands/Delete.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Files.Filesystem;
33
using Files.Helpers;
44
using Files.UserControls;
5+
using Microsoft.Toolkit.Uwp.Extensions;
56
using System;
67
using System.Collections.Generic;
78
using System.Diagnostics;
@@ -83,18 +84,18 @@ public static async void DeleteItemWithStatus(StorageDeleteOption deleteOption)
8384
{
8485
bannerResult.Remove();
8586
App.CurrentInstance.StatusBarControl.OngoingTasksControl.PostBanner(
86-
ResourceController.GetTranslation("AccessDeniedDeleteDialog/Title"),
87-
ResourceController.GetTranslation("AccessDeniedDeleteDialog/Text"),
88-
0,
89-
StatusBanner.StatusBannerSeverity.Error,
87+
"AccessDeniedDeleteDialog/Title".GetLocalized(),
88+
"AccessDeniedDeleteDialog/Text".GetLocalized(),
89+
0,
90+
StatusBanner.StatusBannerSeverity.Error,
9091
StatusBanner.StatusBannerOperation.Delete);
9192
}
9293
catch (FileNotFoundException)
9394
{
9495
bannerResult.Remove();
9596
App.CurrentInstance.StatusBarControl.OngoingTasksControl.PostBanner(
96-
ResourceController.GetTranslation("FileNotFoundDialog/Title"),
97-
ResourceController.GetTranslation("FileNotFoundDialog/Text"),
97+
"FileNotFoundDialog/Title".GetLocalized(),
98+
"FileNotFoundDialog/Text".GetLocalized(),
9899
0,
99100
StatusBanner.StatusBannerSeverity.Error,
100101
StatusBanner.StatusBannerOperation.Delete);
@@ -103,10 +104,10 @@ public static async void DeleteItemWithStatus(StorageDeleteOption deleteOption)
103104
{
104105
bannerResult.Remove();
105106
App.CurrentInstance.StatusBarControl.OngoingTasksControl.PostActionBanner(
106-
ResourceController.GetTranslation("FileInUseDeleteDialog/Title"),
107-
ResourceController.GetTranslation("FileInUseDeleteDialog/Text"),
108-
ResourceController.GetTranslation("FileInUseDeleteDialog/PrimaryButtonText"),
109-
ResourceController.GetTranslation("FileInUseDeleteDialog/SecondaryButtonText"), () => { DeleteItemWithStatus(deleteOption); });
107+
"FileInUseDeleteDialog/Title".GetLocalized(),
108+
"FileInUseDeleteDialog/Text".GetLocalized(),
109+
"FileInUseDeleteDialog/PrimaryButtonText".GetLocalized(),
110+
"FileInUseDeleteDialog/SecondaryButtonText".GetLocalized(), () => { DeleteItemWithStatus(deleteOption); });
110111
}
111112
}
112113

Files/Commands/Paste.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Files.Filesystem;
22
using Files.Helpers;
33
using Files.UserControls;
4+
using Microsoft.Toolkit.Uwp.Extensions;
45
using System;
56
using System.Collections.Generic;
67
using System.Diagnostics;
@@ -65,7 +66,7 @@ private static async Task PasteItem(DataPackageView packageView, string destinat
6566
if (AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath))
6667
{
6768
// Do not paste files and folders inside the recycle bin
68-
await DialogDisplayHelper.ShowDialog(ResourceController.GetTranslation("ErrorDialogThisActionCannotBeDone"), ResourceController.GetTranslation("ErrorDialogUnsupportedOperation"));
69+
await DialogDisplayHelper.ShowDialog("ErrorDialogThisActionCannotBeDone".GetLocalized(), "ErrorDialogUnsupportedOperation".GetLocalized());
6970
return;
7071
}
7172

Files/DataModels/DefaultLanguageModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Globalization;
1+
using Microsoft.Toolkit.Uwp.Extensions;
2+
using System.Globalization;
23

34
namespace Files.DataModels
45
{
@@ -18,7 +19,7 @@ public DefaultLanguageModel(string id)
1819
else
1920
{
2021
ID = string.Empty;
21-
var systemDefaultLanguageOptionStr = ResourceController.GetTranslation("SettingsPreferencesSystemDefaultLanguageOption");
22+
var systemDefaultLanguageOptionStr = "SettingsPreferencesSystemDefaultLanguageOption".GetLocalized();
2223
Name = string.IsNullOrEmpty(systemDefaultLanguageOptionStr) ? "System Default" : systemDefaultLanguageOptionStr;
2324
}
2425
}

Files/Dialogs/AddItemDialog.xaml.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Files.Filesystem;
22
using Files.Helpers;
3+
using Microsoft.Toolkit.Uwp.Extensions;
34
using System;
45
using System.Collections.Generic;
56
using Windows.Storage;
@@ -23,25 +24,25 @@ public void AddItemsToList()
2324

2425
AddItemsList.Add(new AddListItem
2526
{
26-
Header = ResourceController.GetTranslation("AddDialogListFolderHeader"),
27-
SubHeader = ResourceController.GetTranslation("AddDialogListFolderSubHeader"),
27+
Header = "AddDialogListFolderHeader".GetLocalized(),
28+
SubHeader = "AddDialogListFolderSubHeader".GetLocalized(),
2829
Icon = "\xE838",
2930
IsItemEnabled = true,
3031
ItemType = AddItemType.Folder
3132
});
3233

3334
AddItemsList.Add(new AddListItem
3435
{
35-
Header = ResourceController.GetTranslation("AddDialogListTextFileHeader"),
36-
SubHeader = ResourceController.GetTranslation("AddDialogListTextFileSubHeader"),
36+
Header = "AddDialogListTextFileHeader".GetLocalized(),
37+
SubHeader = "AddDialogListTextFileSubHeader".GetLocalized(),
3738
Icon = "\xE8A5",
3839
IsItemEnabled = true,
3940
ItemType = AddItemType.TextDocument
4041
});
4142
AddItemsList.Add(new AddListItem
4243
{
43-
Header = ResourceController.GetTranslation("AddDialogListBitmapHeader"),
44-
SubHeader = ResourceController.GetTranslation("AddDialogListBitmapSubHeader"),
44+
Header = "AddDialogListBitmapHeader".GetLocalized(),
45+
SubHeader = "AddDialogListBitmapSubHeader".GetLocalized(),
4546
Icon = "\xEB9F",
4647
IsItemEnabled = true,
4748
ItemType = AddItemType.BitmapImage
@@ -80,24 +81,24 @@ public static async void CreateFile(AddItemType itemType)
8081
switch (itemType)
8182
{
8283
case AddItemType.Folder:
83-
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewFolder");
84+
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewFolder".GetLocalized();
8485
await folderToCreateItem.CreateFolderAsync(userInput, CreationCollisionOption.GenerateUniqueName);
8586
break;
8687

8788
case AddItemType.TextDocument:
88-
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewTextDocument");
89+
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewTextDocument".GetLocalized();
8990
await folderToCreateItem.CreateFileAsync(userInput + ".txt", CreationCollisionOption.GenerateUniqueName);
9091
break;
9192

9293
case AddItemType.BitmapImage:
93-
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : ResourceController.GetTranslation("NewBitmapImage");
94+
userInput = !string.IsNullOrWhiteSpace(userInput) ? userInput : "NewBitmapImage".GetLocalized();
9495
await folderToCreateItem.CreateFileAsync(userInput + ".bmp", CreationCollisionOption.GenerateUniqueName);
9596
break;
9697
}
9798
}
9899
catch (UnauthorizedAccessException)
99100
{
100-
await DialogDisplayHelper.ShowDialog(ResourceController.GetTranslation("AccessDeniedCreateDialog/Title"), ResourceController.GetTranslation("AccessDeniedCreateDialog/Text"));
101+
await DialogDisplayHelper.ShowDialog("AccessDeniedCreateDialog/Title".GetLocalized(), "AccessDeniedCreateDialog/Text".GetLocalized());
101102
}
102103
}
103104
}

Files/Dialogs/ConfirmDeleteDialog.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.View_Models;
2+
using Microsoft.Toolkit.Uwp.Extensions;
23
using Windows.Storage;
34
using Windows.UI.Xaml;
45
using Windows.UI.Xaml.Controls;
@@ -33,11 +34,11 @@ public ConfirmDeleteDialog(bool deleteFromRecycleBin, StorageDeleteOption delete
3334

3435
if (SelectedItemsPropertiesViewModel.SelectedItemsCount == 1)
3536
{
36-
Description = ResourceController.GetTranslation("ConfirmDeleteDialogDeleteOneItem/Text");
37+
Description = "ConfirmDeleteDialogDeleteOneItem/Text".GetLocalized();
3738
}
3839
else
3940
{
40-
Description = string.Format(ResourceController.GetTranslation("ConfirmDeleteDialogDeleteMultipleItems/Text"), SelectedItemsPropertiesViewModel.SelectedItemsCount);
41+
Description = string.Format("ConfirmDeleteDialogDeleteMultipleItems/Text".GetLocalized(), SelectedItemsPropertiesViewModel.SelectedItemsCount);
4142
}
4243
}
4344

Files/Files.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@
197197
<Compile Include="Helpers\ThemeHelper.cs" />
198198
<Compile Include="Helpers\Win32FindDataExtensions.cs" />
199199
<Compile Include="Program.cs" />
200-
<Compile Include="ResourceController.cs" />
201200
<Compile Include="INavigationToolbar.cs" />
202201
<Compile Include="UserControls\FileIcon.xaml.cs">
203202
<DependentUpon>FileIcon.xaml</DependentUpon>

Files/Filesystem/DriveItem.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ByteSizeLib;
22
using Files.Helpers;
3+
using Microsoft.Toolkit.Uwp.Extensions;
34
using System;
45
using System.Threading.Tasks;
56
using Windows.Storage;
@@ -58,18 +59,18 @@ public DriveItem(StorageFolder root, DriveType type)
5859

5960
SpaceUsed = MaxSpace - FreeSpace;
6061
SpaceText = string.Format(
61-
ResourceController.GetTranslation("DriveFreeSpaceAndCapacity"),
62+
"DriveFreeSpaceAndCapacity".GetLocalized(),
6263
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
6364
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
6465
}
6566
catch (NullReferenceException)
6667
{
67-
SpaceText = ResourceController.GetTranslation("DriveCapacityUnknown");
68+
SpaceText = "DriveCapacityUnknown".GetLocalized();
6869
}
6970
}
7071
else
7172
{
72-
SpaceText = ResourceController.GetTranslation("DriveCapacityUnknown");
73+
SpaceText = "DriveCapacityUnknown".GetLocalized();
7374
}
7475
}
7576

Files/Filesystem/Drives.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Files.View_Models;
22
using Files.Views;
33
using Microsoft.Toolkit.Mvvm.ComponentModel;
4+
using Microsoft.Toolkit.Uwp.Extensions;
45
using NLog;
56
using System;
67
using System.Collections.Generic;
@@ -70,9 +71,9 @@ private async void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, obje
7071
{
7172
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
7273
{
73-
if (MainPage.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == ResourceController.GetTranslation("SidebarDrives")) == null)
74+
if (MainPage.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarDrives".GetLocalized()) == null)
7475
{
75-
MainPage.sideBarItems.Add(new HeaderTextItem() { Text = ResourceController.GetTranslation("SidebarDrives") });
76+
MainPage.sideBarItems.Add(new HeaderTextItem() { Text = "SidebarDrives".GetLocalized() });
7677
}
7778
foreach (DriveItem drive in Drives)
7879
{
@@ -101,9 +102,9 @@ private async void MainView_Activated(CoreApplicationView sender, Windows.Applic
101102
{
102103
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
103104
{
104-
if (MainPage.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == ResourceController.GetTranslation("SidebarDrives")) == null)
105+
if (MainPage.sideBarItems.FirstOrDefault(x => x is HeaderTextItem && x.Text == "SidebarDrives".GetLocalized()) == null)
105106
{
106-
MainPage.sideBarItems.Add(new HeaderTextItem() { Text = ResourceController.GetTranslation("SidebarDrives") });
107+
MainPage.sideBarItems.Add(new HeaderTextItem() { Text = "SidebarDrives".GetLocalized() });
107108
}
108109
foreach (DriveItem drive in Drives)
109110
{

0 commit comments

Comments
 (0)