Skip to content

Commit b0ea017

Browse files
authored
Code Quality: Convert Multiple Localized Strings to ICU Message Format | Stage One (#15507)
1 parent 895331a commit b0ea017

File tree

2 files changed

+31
-60
lines changed

2 files changed

+31
-60
lines changed

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,47 +1226,38 @@
12261226
<data name="Copy" xml:space="preserve">
12271227
<value>Copy</value>
12281228
</data>
1229-
<data name="CopyItemsDialogSubtitleMultiple" xml:space="preserve">
1230-
<value>{0} items will be copied</value>
1231-
</data>
12321229
<data name="CopyItemsDialogTitle" xml:space="preserve">
1233-
<value>Copy item(s)</value>
1230+
<value>Copy {0, plural, one {item} other {items}}</value>
12341231
</data>
12351232
<data name="DeleteItemsDialogTitle" xml:space="preserve">
1236-
<value>Delete item(s)</value>
1233+
<value>Delete {0, plural, one {item} other {items}}</value>
12371234
</data>
12381235
<data name="MoveItemsDialogPrimaryButtonText" xml:space="preserve">
12391236
<value>Move</value>
12401237
</data>
1241-
<data name="MoveItemsDialogSubtitleMultiple" xml:space="preserve">
1242-
<value>{0} items will be moved</value>
1238+
<data name="MoveItemsDialogSubtitle" xml:space="preserve">
1239+
<value>{0, plural, one {One item will be moved} other {# items will be moved}}</value>
12431240
</data>
12441241
<data name="MoveItemsDialogTitle" xml:space="preserve">
1245-
<value>Move item(s)</value>
1242+
<value>Move {0, plural, one {item} other {items}}</value>
12461243
</data>
1247-
<data name="DeleteItemsDialogSubtitleMultiple" xml:space="preserve">
1248-
<value>{0} items will be deleted</value>
1244+
<data name="DeleteItemsDialogSubtitle" xml:space="preserve">
1245+
<value>{0, plural, one {One item will be deleted} other {# items will be deleted}}</value>
12491246
</data>
12501247
<data name="ConflictingItemsDialogPrimaryButtonText" xml:space="preserve">
12511248
<value>Continue</value>
12521249
</data>
1253-
<data name="ConflictingItemsDialogSubtitleMultipleConflictsMultipleNonConflicts" xml:space="preserve">
1254-
<value>There are {0} conflicting file names, and {1} outgoing item(s).</value>
1255-
</data>
1256-
<data name="ConflictingItemsDialogTitle" xml:space="preserve">
1257-
<value>Conflicting file name(s)</value>
1258-
</data>
1259-
<data name="ConflictingItemsDialogSubtitleSingleConflictMultipleNonConflicts" xml:space="preserve">
1260-
<value>There is one conflicting file name, and {0} outgoing item(s).</value>
1250+
<data name="ConflictingItemsDialogSubtitleConflicts" xml:space="preserve">
1251+
<value>{0, plural, one {There is one conflicting file name} other {There are # conflicting file names}}</value>
12611252
</data>
1262-
<data name="CopyItemsDialogSubtitleSingle" xml:space="preserve">
1263-
<value>One item will be copied</value>
1253+
<data name="ConflictingItemsDialogSubtitleConflictsNonConflicts" xml:space="preserve">
1254+
<value>{0, plural, one {, and one outgoing item} other {, and # outgoing items}}</value>
12641255
</data>
1265-
<data name="DeleteItemsDialogSubtitleSingle" xml:space="preserve">
1266-
<value>One item will be deleted</value>
1256+
<data name="ConflictingItemsDialogTitle" xml:space="preserve">
1257+
<value>Conflicting {0, plural, one {file name} other {file names}}</value>
12671258
</data>
1268-
<data name="MoveItemsDialogSubtitleSingle" xml:space="preserve">
1269-
<value>One item will be moved</value>
1259+
<data name="CopyItemsDialogSubtitle" xml:space="preserve">
1260+
<value>{0, plural, one {One item will be copied} other {# items will be copied}}</value>
12701261
</data>
12711262
<data name="DeleteItemsDialogPermanentlyDeleteCheckBox.Content" xml:space="preserve">
12721263
<value>Permanently delete</value>
@@ -1280,12 +1271,6 @@
12801271
<data name="GenerateNewName" xml:space="preserve">
12811272
<value>Generate new name</value>
12821273
</data>
1283-
<data name="ConflictingItemsDialogSubtitleMultipleConflictsNoNonConflicts" xml:space="preserve">
1284-
<value>There are {0} conflicting file names.</value>
1285-
</data>
1286-
<data name="ConflictingItemsDialogSubtitleSingleConflictNoNonConflicts" xml:space="preserve">
1287-
<value>There is one conflicting file name.</value>
1288-
</data>
12891274
<data name="CreateFolderWithSelection" xml:space="preserve">
12901275
<value>Create folder with selection</value>
12911276
</data>

src/Files.App/ViewModels/Dialogs/FileSystemDialog/FileSystemDialogViewModel.cs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Files.App.Data.Enums;
55
using Files.Shared.Extensions;
6+
using System.Text;
67

78
namespace Files.App.ViewModels.Dialogs.FileSystemDialog
89
{
@@ -144,26 +145,20 @@ public static FileSystemDialogViewModel GetDialogViewModel(FileSystemDialogMode
144145
var primaryButtonText = string.Empty;
145146
var secondaryButtonText = string.Empty;
146147
var isInDeleteMode = false;
148+
var totalCount = nonConflictingItems.Count + conflictingItems.Count;
147149

148150
if (dialogMode.ConflictsExist)
149151
{
150-
// Subtitle text
151-
if (conflictingItems.Count > 1)
152-
{
153-
var descriptionLocalized = (nonConflictingItems.Count > 0)
154-
? "ConflictingItemsDialogSubtitleMultipleConflictsMultipleNonConflicts".ToLocalized()
155-
: "ConflictingItemsDialogSubtitleMultipleConflictsNoNonConflicts".ToLocalized();
152+
titleText = "ConflictingItemsDialogTitle".GetLocalizedFormatResource(totalCount);
156153

157-
descriptionText = string.Format(descriptionLocalized, conflictingItems.Count, nonConflictingItems.Count);
158-
}
159-
else
160-
{
161-
descriptionText = (nonConflictingItems.Count > 0)
162-
? string.Format("ConflictingItemsDialogSubtitleSingleConflictMultipleNonConflicts".ToLocalized(), nonConflictingItems.Count)
163-
: string.Format("ConflictingItemsDialogSubtitleSingleConflictNoNonConflicts".ToLocalized(), conflictingItems.Count);
164-
}
154+
var descriptionLocalized = new StringBuilder();
155+
descriptionLocalized.Append("ConflictingItemsDialogSubtitleConflicts".GetLocalizedFormatResource(conflictingItems.Count));
165156

166-
titleText = "ConflictingItemsDialogTitle".ToLocalized();
157+
if (nonConflictingItems.Count > 0)
158+
descriptionLocalized.Append("ConflictingItemsDialogSubtitleConflictsNonConflicts".GetLocalizedFormatResource(nonConflictingItems.Count));
159+
160+
descriptionLocalized.Append('.');
161+
descriptionText = descriptionLocalized.ToString();
167162
primaryButtonText = "ConflictingItemsDialogPrimaryButtonText".ToLocalized();
168163
secondaryButtonText = "Cancel".ToLocalized();
169164
}
@@ -173,12 +168,9 @@ public static FileSystemDialogViewModel GetDialogViewModel(FileSystemDialogMode
173168
{
174169
case FilesystemOperationType.Copy:
175170
{
176-
titleText = "CopyItemsDialogTitle".ToLocalized();
177-
178-
descriptionText = (nonConflictingItems.Count + conflictingItems.Count == 1)
179-
? "CopyItemsDialogSubtitleSingle".ToLocalized()
180-
: string.Format("CopyItemsDialogSubtitleMultiple".ToLocalized(), nonConflictingItems.Count + conflictingItems.Count);
171+
titleText = "CopyItemsDialogTitle".GetLocalizedFormatResource(totalCount);
181172

173+
descriptionText = "CopyItemsDialogSubtitle".GetLocalizedFormatResource(totalCount);
182174
primaryButtonText = "Copy".ToLocalized();
183175
secondaryButtonText = "Cancel".ToLocalized();
184176

@@ -187,12 +179,9 @@ public static FileSystemDialogViewModel GetDialogViewModel(FileSystemDialogMode
187179

188180
case FilesystemOperationType.Move:
189181
{
190-
titleText = "MoveItemsDialogTitle".ToLocalized();
191-
192-
descriptionText = (nonConflictingItems.Count + conflictingItems.Count == 1)
193-
? "MoveItemsDialogSubtitleSingle".ToLocalized()
194-
: string.Format("MoveItemsDialogSubtitleMultiple".ToLocalized(), nonConflictingItems.Count + conflictingItems.Count);
182+
titleText = "MoveItemsDialogTitle".GetLocalizedFormatResource(totalCount);
195183

184+
descriptionText = "MoveItemsDialogSubtitle".GetLocalizedFormatResource(totalCount);
196185
primaryButtonText = "MoveItemsDialogPrimaryButtonText".ToLocalized();
197186
secondaryButtonText = "Cancel".ToLocalized();
198187

@@ -201,12 +190,9 @@ public static FileSystemDialogViewModel GetDialogViewModel(FileSystemDialogMode
201190

202191
case FilesystemOperationType.Delete:
203192
{
204-
titleText = "DeleteItemsDialogTitle".ToLocalized();
205-
206-
descriptionText = (nonConflictingItems.Count + conflictingItems.Count == 1)
207-
? "DeleteItemsDialogSubtitleSingle".ToLocalized()
208-
: string.Format("DeleteItemsDialogSubtitleMultiple".ToLocalized(), nonConflictingItems.Count);
193+
titleText = "DeleteItemsDialogTitle".GetLocalizedFormatResource(totalCount);
209194

195+
descriptionText = "DeleteItemsDialogSubtitle".GetLocalizedFormatResource(totalCount);
210196
primaryButtonText = "Delete".ToLocalized();
211197
secondaryButtonText = "Cancel".ToLocalized();
212198

0 commit comments

Comments
 (0)