Background:
The reason of this question is a difference between Localization's IStringLocalizer and Mvc.Localization's IViewLocalizer which I noticed last week, or rather in their official implementations (ResourceManagerStringLocalizer and ViewLocalizer).
Initially I created a PR in Localization (aspnet/Mvc#5962) since I think of this as a bug, during review @dougbu @pranavkm pointed out that intended behavior isn't clear. Before deciding on a way to change this, since it would break the currently shipped behavior, it should be clarified here in the Localization repo so the right approach can be chosen.
The ResourceManagerStringLocalizer behaves like this:
this[name] -> returns raw string
this[name, arguments] -> returns string.format of raw string and arguments
The ViewLocalizer like this:
this[name] -> returns string.format of raw string with empty arguments
this[name, arguments] -> returns string.format of raw string and arguments
Actually a LocalizedHtmlString, however during response rendering it's changed to the described behavior when WriteTo is called.
There is also a code example of this here: https://github.com/hiiru/LocalizationBugExample
Before creating this issue I looked at the tests, comments and documentation of Localization, however I didn't find anything that explicitly describes the behavior.
Also I didn't see any test for the this[name, arguments] signature at all (based on dev branch), nor is any test related to formatted strings.
In my opinion, I think the IStringLocalizer implies the current behavior of ResourceManagerStringLocalizer due to the minor comment difference between both this[] comments.
Also I wouldn't expect a string.format when I don't provide arguments.
Question:
What is the intended behavior of IStringLocalizer's this[name]?
Should this return a raw string or a formatted string?
Background:
The reason of this question is a difference between Localization's
IStringLocalizerand Mvc.Localization'sIViewLocalizerwhich I noticed last week, or rather in their official implementations (ResourceManagerStringLocalizerandViewLocalizer).Initially I created a PR in Localization (aspnet/Mvc#5962) since I think of this as a bug, during review @dougbu @pranavkm pointed out that intended behavior isn't clear. Before deciding on a way to change this, since it would break the currently shipped behavior, it should be clarified here in the Localization repo so the right approach can be chosen.
The
ResourceManagerStringLocalizerbehaves like this:this[name] -> returns raw string
this[name, arguments] -> returns string.format of raw string and arguments
The
ViewLocalizerlike this:this[name] -> returns string.format of raw string with empty arguments
this[name, arguments] -> returns string.format of raw string and arguments
Actually a
LocalizedHtmlString, however during response rendering it's changed to the described behavior when WriteTo is called.There is also a code example of this here: https://github.com/hiiru/LocalizationBugExample
Before creating this issue I looked at the tests, comments and documentation of Localization, however I didn't find anything that explicitly describes the behavior.
Also I didn't see any test for the this[name, arguments] signature at all (based on dev branch), nor is any test related to formatted strings.
In my opinion, I think the
IStringLocalizerimplies the current behavior ofResourceManagerStringLocalizerdue to the minor comment difference between both this[] comments.Also I wouldn't expect a string.format when I don't provide arguments.
Question:
What is the intended behavior of
IStringLocalizer's this[name]?Should this return a raw string or a formatted string?