Skip to content

Commit b1d6168

Browse files
author
Kapil Borle
committed
Localize error strings in Position class
1 parent 064eb77 commit b1d6168

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

Engine/Position.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23

34
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
45
{
@@ -10,12 +11,16 @@ public Position(int line, int column)
1011
{
1112
if (line < 1)
1213
{
13-
throw new ArgumentException("line cannot be less than 1.", nameof(line));
14+
throw new ArgumentException(
15+
String.Format(CultureInfo.CurrentCulture, Strings.PositionLineLessThanOne),
16+
nameof(line));
1417
}
1518

1619
if (column < 1)
1720
{
18-
throw new ArgumentException("line cannot be less than 1.", nameof(line));
21+
throw new ArgumentException(
22+
String.Format(CultureInfo.CurrentCulture, Strings.PositionColumnLessThanOne),
23+
nameof(column));
1924
}
2025

2126
Line = line;
@@ -38,24 +43,20 @@ public Position Shift(int lineDelta, int columnDelta)
3843
int newLine = Line;
3944
int newColumn = Column;
4045

41-
if (lineDelta != 0)
46+
newLine += lineDelta;
47+
if (newLine < 1)
4248
{
43-
newLine += lineDelta;
44-
if (newLine < 1)
45-
{
46-
throw new ArgumentException("Invalid line delta. Resulting start line number must be greather than 1.");
47-
48-
}
49+
throw new ArgumentException(
50+
String.Format(CultureInfo.CurrentCulture, Strings.PositionLineLessThanOne),
51+
nameof(lineDelta));
4952
}
5053

51-
if (columnDelta != 0)
54+
newColumn += columnDelta;
55+
if (newColumn < 1)
5256
{
53-
newColumn += columnDelta;
54-
if (newColumn < 1)
55-
{
56-
throw new ArgumentException("Invalid column delta. Resulting start column number must be greather than 1.");
57-
58-
}
57+
throw new ArgumentException(
58+
String.Format(CultureInfo.CurrentCulture, Strings.PositionColumnLessThanOne),
59+
nameof(columnDelta));
5960
}
6061

6162
return new Position(newLine, newColumn);
@@ -75,7 +76,9 @@ public static Position Normalize(Position refPos, Position pos)
7576

7677
if (pos < refPos)
7778
{
78-
throw new ArgumentException("input should be less than that of the invoking object.");
79+
throw new ArgumentException(String.Format(
80+
CultureInfo.CurrentCulture,
81+
Strings.PositionRefPosLessThanInputPos));
7982
}
8083

8184
if (pos.Line == refPos.Line)

Engine/Strings.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,13 @@
309309
<data name="RangeRefPosShouldStartBeforeRangeStartPos" xml:space="preserve">
310310
<value>Reference Position should begin before start Position of Range.</value>
311311
</data>
312+
<data name="PositionLineLessThanOne" xml:space="preserve">
313+
<value>Line number cannot be less than 1.</value>
314+
</data>
315+
<data name="PositionColumnLessThanOne" xml:space="preserve">
316+
<value>Column number cannot be less than 1.</value>
317+
</data>
318+
<data name="PositionRefPosLessThanInputPos" xml:space="preserve">
319+
<value>Input position should be less than that of the invoking object.</value>
320+
</data>
312321
</root>

0 commit comments

Comments
 (0)