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-* also localize tag's content #33

Closed morgrowe closed 2 years ago

morgrowe commented 2 years ago

Hi Ziya

Hope you're well.

Whenever I use the localize-att- tag helper, not only does it localize the attribute's value, but the tag's contents as well. For example:

<p localize-att-title="foo">bar</p>

Returns this in the console:

warn: XLocalizer.DB.EF.EFDbResourceProvider[0]
      Resource not exist! Culture: 'cy', Key: 'foo'
warn: XLocalizer.DB.EF.EFDbResourceProvider[0]
      Resource not exist! Culture: 'cy', Key: 'bar'

I'd expect it to log:

warn: XLocalizer.DB.EF.EFDbResourceProvider[0]
      Resource not exist! Culture: 'cy', Key: 'foo'

I'm using the localize-att-* extensively in my project and I'd like to reduce the amount of redundant database traffic. A real world example would be localizing Bootstrap's "close" label. I only want to localize the aria-label attribute, not the content of the tag (as it's just an icon).

<button type="button" class="close" data-dismiss="modal" localize-att-aria-label="Close">
    <span aria-hidden="true">&times;</span>
</button>

I expect only one request to fetch the resource with the key "Close", but instead I get two. One for "Close" and another for "<span aria-hidden="true">&times;</span>".

Is this working as intended? If so, would it be possible to add an option to only localize the tag's contents when localize-content is added to the tag please?

Package versions:

<PackageReference Include="XLocalizer" Version="1.0.3" />
<PackageReference Include="XLocalizer.DB" Version="1.0.3" />
<PackageReference Include="XLocalizer.TagHelpers" Version="1.1.0" />

Cheers Morgan

LazZiya commented 2 years ago

Hi @morgrowe ,

Nice to see you again :)

Just use localize-content="false":

<p localize-att-title="foo" localize-content="false">bar</p>
morgrowe commented 2 years ago

Thanks for the incredibly fast response :). Awesome, localize-content="false" works perfectly. Thank you!

Would it be possible to have this as the default behaviour? I can see why some people would like to have the implicit local-content behaviour when using the localize-att- tag helper, but I think it would be extremely handy if this behaviour could be disabled.

Cheers Morgan

LazZiya commented 2 years ago

you are welcome :)

I will take your comment into consideration during the next update.

Best, Ziya

morgrowe commented 2 years ago

Great, thank you. :)

Morgan