0
votes

I have a static class:

public static class MyDict
    {
        public static IEnumerable<string> fruits = new string[] { "Apple", "Banana", "Cherry" };
        public static IEnumerable<string> vegetables = new string[] { "Carrot", "Tomato", "Cabbage" };
    }

That is easily used from the View:

<select asp-for="Fruits" asp-items="@(new SelectList(@ListingDict.fruits ))"></select>

Now I also need a localized (French) list of fruits. I know how to inject IStringLocalizer/IHtmlLocalizer/IViewLocalizer into the view, and for simple strings I use @Localizer("Foo"). But what is the best way for handling string arrays? Do I need to get away from the static MyDict and instead inject IStringLocalizer into the MyDict instance, but then what? Localize each item of the array individuality, e.g. {_localizer("Apple"), _localizer("Banana")}?

I really like the simplicity I have now with just a static lookup class, but I don't think it works with localization. What is the best approach here? How do you store string arrays in the resources file?

Thanks

1

1 Answers

0
votes

Create a single model holding your desired properties with localization values, then inject it into the view or add it as a model or add separate View Components with different contents