AspNetCoreLocalization icon indicating copy to clipboard operation
AspNetCoreLocalization copied to clipboard

Why stringLocalizer arguments are not used

Open JanneHarju opened this issue 6 years ago • 4 comments

It seems that second version of _localizer["Thing {jep}", jep] is not using arguments at all. https://github.com/damienbod/AspNetCoreLocalization/blob/master/src/Localization.SqlLocalizer/DbStringLocalizer/SqlStringLocalizer.cs#L36 Is there something I need to know about C# or is this just in todo phase. I believe that there should be few more lines in that method like this.

var localicedString = this[name];
return new LocalizedString(name, String.Format(localicedString.Value, arguments), localicedString.ResourceNotFound);

JanneHarju avatar Apr 17 '19 10:04 JanneHarju

will be released in next version

damienbod avatar Apr 30 '19 09:04 damienbod

We're in April 2021, three versions later, but this issue still hasn't been fixed. Is there any chance this will get fixed soon ?

daniel-jann avatar Apr 15 '21 07:04 daniel-jann

Hi @daniel-jann I'll look at this again. Maybe if you know how to fix it, you could do a PR?

I don't have so much time at the moment

Greetings Damien

damienbod avatar Apr 15 '21 12:04 damienbod

https://github.com/damienbod/AspNetCoreLocalization/blob/a362dc73be13cdfb2ee83bd1a8fa9b440ea00e74/src/Localization.SqlLocalizer/DbStringLocalizer/SqlStringLocalizer.cs#L41

parameters work as follows

using System.Linq;
public LocalizedString this[string name, params object[] arguments]
        {
            get
            {
                var localizedString = this[name];
                return new LocalizedString(name, String.Format(localizedString.Value, arguments.Select(x => x.ToString()).ToArray()), localizedString.ResourceNotFound);
            }
        }
new LocalizationRecord(){ Key="RequiredError", ResourceKey="global", Text="The {0} field is required.", LocalizationCulture="en-GB" },
new LocalizationRecord(){ Key="Name", ResourceKey="global", Text="Name", LocalizationCulture="en-GB" },

[Required(ErrorMessage = "RequiredError")]
[Display(Name = "Name")] 
public string Name { get; set; }

suatsuphi avatar May 17 '21 18:05 suatsuphi