XLocalizer icon indicating copy to clipboard operation
XLocalizer copied to clipboard

Curly braces in string cause error

Open julianadormon opened this issue 7 months ago • 1 comments

Hi! I hope you're well. I am getting the following error when the string includes curly braces.

Here is the code (running on Blazor server) version 1.0.3 with Google translate 1.0.1: @if (!string.IsNullOrEmpty(Model.Product?.Description)) {

@Localizer[Model.Product.Description]
}

Here is the actual string value (there is \r\n before the curly brace, but other values using line breaks work ok): 8x10 Memory Mate {4} Wallets (same pose as memory mate individual image)

Here is the error: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan1 args) at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan1 args) at XLocalizer.XStringLocalizer`1.GetLocalizedString(String name, Object[] arguments) at ProofpixClient.Shared.PricelistProductCard.<BuildRenderTree>b__0_0(RenderTreeBuilder __builder2) in /Users/macminim1/Projects/Proofpix-V2/ProofpixClient/Shared/PricelistProductCard.razor:line 81 at Radzen.Blazor.RadzenCard.BuildRenderTree(RenderTreeBuilder __builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

Thanks for looking into this.

Image

julianadormon avatar May 15 '25 11:05 julianadormon

Hi @julianadormon ,

Looking at the provided string in the screenshot, it has this placeholder "{4}", it should be "{0}" cuz there is only one value. Also make sure you provide the relevant argument as necessary.

LazZiya avatar May 15 '25 11:05 LazZiya