LazZiya / XLocalizer

Localizer package for Asp.Net Core web applications, powered by online translation and auto resource creating.
https://docs.ziyad.info
128 stars 14 forks source link

Is it possible to localize <select asp-items />? #27

Closed morgrowe closed 3 years ago

morgrowe commented 3 years ago

Hi Ziya,

Hope you're well.

Is it possible to localize the contents of a <select asp-items /> automatically?

For example, in a View:

@{
    var items = new List<SelectListItem>();
    items.Add(new SelectListItem
    {
        Text = "Some string to be localized", 
        Value = "SomeValue" 
    });
}
...
<select asp-items="@items"></select>
...

I'm not sure where I'd put the localize-content or localize-att-* to tell it to do its magic.

I haven't tried it, but as a work around, I imagine I could omit the asp-items and do it something like this:

<select asp-items="@items">
    @foreach (var item in items)
    {
        <option value="@item.Value" localize-content>@item.Text</option>
    }
</select>

But I thought I'd ask in case this is isn't required. :)

Thanks, as always. Morgan

LazZiya commented 3 years ago

Hi @morgrowe

Sorry I’m not able to offer a solution now due to some health issues :( may be after two weeks I will be able to help.

morgrowe commented 3 years ago

Hi Ziya,

Sorry to hear you're not well. I hope you get well soon.

No problem at all--don't even think about it. I'm more than happy to use the workaround :)

Morgan

LazZiya commented 3 years ago

Hi @morgrowe ,

Thank you for your kindness, finally I have recovered and feeling better now :)

Your workaround is correct, but this issue inspired me to create a new tag helper...

Best regards, Ziya

morgrowe commented 3 years ago

Hi Ziya,

Glad to hear you're feeling better. :)

Ok great, that enhancement will be extremely useful. Thank you!

Morgan