LazZiya / XLocalizer

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

localize-att- and localize-att-args- #25

Closed morgrowe closed 3 years ago

morgrowe commented 3 years ago

Hi Ziya

Hope you're well.

I'm trying to localize an attribute with arguments. To achieve something like this:

<input placeholder="Please provide your name"/>

I was hoping to something like:

<input localize-att-placeholder="Please provide your {0}" />

But I can't figure out how to pass the arguments to localize-att-. Is this possible? I've probably missed it in the docs.

Thanks as always, Morgan

LazZiya commented 3 years ago

Hi @morgrowe ,

I'm fine thanks, hope you are fine too :)

Unfortunately it is not possible now to use arguments with the localize-att-, it takes only string with no arguments :(

As a workaround you can put the formatted string in a hidden element then assign it to the placeholder, something like below:

<span id="placeholder-msg" class="d-none" localize-args="new[] { "name" }">
Please provide your {0}
</span>

<input id="my-input" placeholder=""/>

<script>
    $(function() {
        var msg = $("#placeholder-msg").text();
        $("$my-input").attr("placeholder", msg);
    });
</script>
morgrowe commented 3 years ago

Ok cool, no problem at all.

Thanks for the JavaScript work-around and for the quick response. :)

Thanks Morgan

LazZiya commented 3 years ago

you are welcome :)