Skip to content

Commit 5293675

Browse files
author
Kapil Borle
committed
Localize error strings
Localizes error strings in the following classes. - TextLines - TextEdit - EditableText
1 parent bf4c44f commit 5293675

5 files changed

Lines changed: 33 additions & 33 deletions

File tree

Engine/EditableText.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Globalization;
45
using System.Linq;
56
using System.Management.Automation.Language;
67
using System.Text;
@@ -126,34 +127,12 @@ private void ValidateTextEditExtent(TextEdit textEdit)
126127
|| textEdit.StartColumnNumber > Lines[textEdit.StartLineNumber - 1].Length
127128
|| textEdit.EndColumnNumber > Lines[textEdit.EndLineNumber - 1].Length + 1)
128129
{
129-
// TODO Localize
130-
throw new ArgumentException("TextEdit extent not completely contained in EditableText.");
130+
throw new ArgumentException(String.Format(
131+
CultureInfo.CurrentCulture,
132+
Strings.EditableTextRangeIsNotContained));
131133
}
132134
}
133135

134-
private int GetOffset(int lineNumber, int columnNumber)
135-
{
136-
if (lineNumber < 1)
137-
{
138-
throw new ArgumentException("Line number must be greater than 0.", nameof(lineNumber));
139-
}
140-
141-
if (columnNumber < 1)
142-
{
143-
throw new ArgumentException("Column number must be greater than 0.", nameof(lineNumber));
144-
}
145-
146-
var zeroBasedLineNumber = lineNumber - 1;
147-
var zeroBasedColumnNumber = columnNumber - 1;
148-
var offset = 0;
149-
for (var k = 0; k < zeroBasedLineNumber; k++)
150-
{
151-
offset += Lines[k].Length + NewLine.Length;
152-
}
153-
154-
return offset + zeroBasedColumnNumber;
155-
}
156-
157136
private static string GetNewLineCharacters(string text, out string[] lines)
158137
{
159138
int numNewLineChars = GetNumNewLineCharacters(text, out lines);
@@ -178,8 +157,9 @@ private static int GetNumNewLineCharacters(string text, out string[] lines)
178157
int remainder = numCharDiff % (lines.Length - 1);
179158
if (remainder != 0)
180159
{
181-
// TODO localize
182-
throw new ArgumentException("Cannot determine line endings as the text probably contain mixed line endings.", nameof(text));
160+
throw new ArgumentException(
161+
String.Format(CultureInfo.CurrentCulture, Strings.EditableTextInvalidLineEnding),
162+
nameof(text));
183163
}
184164

185165
return numCharDiff / (lines.Length - 1);

Engine/Strings.resx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,19 @@
291291
<data name="ConfigurableScriptRuleNRE" xml:space="preserve">
292292
<value>"Argument should not be null.".</value>
293293
</data>
294-
</root>
294+
<data name="TextLinesNoNullItem" xml:space="preserve">
295+
<value>Line element cannot be null.</value>
296+
</data>
297+
<data name="TextEditNoNullItem" xml:space="preserve">
298+
<value>Line element cannot be null.</value>
299+
</data>
300+
<data name="EditableTextRangeIsNotContained" xml:space="preserve">
301+
<value>TextEdit extent not completely contained in EditableText.</value>
302+
</data>
303+
<data name="EditableTextRangeIsNotContained" xml:space="preserve">
304+
<value>TextEdit extent not completely contained in EditableText.</value>
305+
</data>
306+
<data name="EditableTextInvalidLineEnding" xml:space="preserve">
307+
<value>Cannot determine line endings as the text probably contain mixed line endings.</value>
308+
</data>
309+
</root>

Engine/TextEdit.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions;
56

@@ -86,8 +87,9 @@ public TextEdit(
8687

8788
if (lines.Any(line => line == null))
8889
{
89-
// TODO localize
90-
throw new ArgumentException("Lines cannot contain a null element.", nameof(lines));
90+
throw new ArgumentException(
91+
String.Format(CultureInfo.CurrentCulture,
92+
Strings.TextEditNoNullItem), nameof(lines));
9193
}
9294

9395
Lines = lines.ToArray();

Engine/TextLines.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Globalization;
45
using System.Linq;
56

67
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
@@ -41,8 +42,10 @@ public TextLines(IEnumerable<string> inputLines) : this()
4142
ThrowIfNull(inputLines, nameof(inputLines));
4243
if (inputLines.Any(line => line == null))
4344
{
44-
// todo localize
45-
throw new ArgumentException("Line element cannot be null.");
45+
throw new ArgumentException(String.Format(
46+
CultureInfo.CurrentCulture,
47+
Strings.TextLinesNoNullItem));
48+
4649
}
4750

4851
lines = new LinkedList<string>(inputLines);

Rules/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,4 @@
954954
<data name="UseSupportsShouldProcessError" xml:space="preserve">
955955
<value>Whatif and/or Confirm manually defined in function {0}. Instead, please use SupportsShouldProcess attribute.</value>
956956
</data>
957-
</root>
957+
</root>

0 commit comments

Comments
 (0)