|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using System.Globalization;
|
8 | 8 | using SmartFormat.Core.Extensions;
|
| 9 | +using SmartFormat.Core.Output; |
9 | 10 | using SmartFormat.Core.Parsing;
|
| 11 | +using SmartFormat.Pooling.SmartPools; |
10 | 12 | using SmartFormat.Utilities;
|
11 | 13 |
|
12 | 14 | namespace SmartFormat.Extensions;
|
@@ -68,6 +70,21 @@ public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
68 | 70 | // Get the localized string
|
69 | 71 | var localized = LocalizationProvider!.GetString(formattingInfo.Format!.RawText, cultureInfo);
|
70 | 72 |
|
| 73 | + // Try formatting if localized string was not found, but a format has nested items |
| 74 | + if (localized is null && formattingInfo.Format!.HasNested) |
| 75 | + { |
| 76 | + using var zsOutput = new ZStringOutput(ZStringBuilderExtensions.CalcCapacity(formattingInfo.Format)); |
| 77 | + |
| 78 | + var localizableFormatDetails = FormatDetailsPool.Instance.Get().Initialize(_formatter!, |
| 79 | + formattingInfo.Format, InitializationObject.ObjectList, null, zsOutput); |
| 80 | + var localizableFormattingInfo = FormattingInfoPool.Instance.Get().Initialize(localizableFormatDetails, |
| 81 | + formattingInfo.Format, formattingInfo.CurrentValue); |
| 82 | + |
| 83 | + _formatter!.Format(localizableFormattingInfo); |
| 84 | + |
| 85 | + localized = LocalizationProvider!.GetString(zsOutput.ToString(), cultureInfo); |
| 86 | + } |
| 87 | + |
71 | 88 | if (localized is null) throw new LocalizationFormattingException(formattingInfo.Format, $"No localized string found for '{formattingInfo.Format!.RawText}'", formattingInfo.Format.StartIndex);
|
72 | 89 |
|
73 | 90 | // Use an existing Format from the cache
|
|
0 commit comments