Skip to content

Commit 671fc75

Browse files
committed
Support alignment format string & Improve documents
1 parent ce8ff62 commit 671fc75

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ private static List<LocalizableStringParam> GetParameters(string format)
190190
i++; // Move past '{'
191191
int index = 0;
192192
bool hasIndex = false;
193+
193194
// Parse index
194195
while (i < len && char.IsDigit(format[i]))
195196
{
196197
hasIndex = true;
197198
index = index * 10 + (format[i] - '0');
198199
i++;
199200
}
201+
200202
if (!hasIndex)
201203
{
202204
// Skip invalid format item
@@ -210,8 +212,25 @@ private static List<LocalizableStringParam> GetParameters(string format)
210212
}
211213
continue;
212214
}
213-
// Check for colon to parse format
215+
216+
// Check for alignment (comma followed by optional sign and digits)
217+
if (i < len && format[i] == ',')
218+
{
219+
i++; // Skip comma and optional sign
220+
if (i < len && (format[i] == '+' || format[i] == '-'))
221+
{
222+
i++;
223+
}
224+
// Skip digits
225+
while (i < len && char.IsDigit(format[i]))
226+
{
227+
i++;
228+
}
229+
}
230+
214231
string formatPart = null;
232+
233+
// Check for format (after colon)
215234
if (i < len && format[i] == ':')
216235
{
217236
i++; // Move past ':'
@@ -243,6 +262,7 @@ private static List<LocalizableStringParam> GetParameters(string format)
243262
i++; // Move past '}'
244263
}
245264
}
265+
246266
parameters[index] = formatPart;
247267
if (index > maxIndex)
248268
{
@@ -255,11 +275,11 @@ private static List<LocalizableStringParam> GetParameters(string format)
255275
// Handle possible escaped '}}'
256276
if (i + 1 < len && format[i + 1] == '}')
257277
{
258-
i += 2;
278+
i += 2; // Skip escaped '}}'
259279
}
260280
else
261281
{
262-
i++;
282+
i++; // Move past '}'
263283
}
264284
}
265285
else
@@ -274,7 +294,7 @@ private static List<LocalizableStringParam> GetParameters(string format)
274294
{
275295
return result;
276296
}
277-
297+
278298
for (int idx = 0; idx <= maxIndex; idx++)
279299
{
280300
var formatValue = parameters.TryGetValue(idx, out var value) ? value : null;

0 commit comments

Comments
 (0)