jsakamoto / Toolbelt.Blazor.I18nText

The class library that provides the ability to localize texts on your Blazor app!
Mozilla Public License 2.0
247 stars 25 forks source link

adding option of pulling properties by name via reflection #55

Closed stancoffyn closed 2 years ago

stancoffyn commented 2 years ago

I have a use case where I would like to use the i18n features on a product page and have specific product translations in the json document.

I am of the mind that a product with an ID of 1234 could have configurations in the translation document as follows

{
   'product1234name' : 'my happy new product',
   'product1234description' : 'product description english...'
}

What I would like to be able to do is as follows:

<h1>@Products.GetValueByName($"product{product.Id}name")</h1>

This way products can be defined in the database, but translations could be performed outside of doing database changes. So long as the key is unchanged, compile time changes would not be required as they are loaded from the json doc.

Thoughts?

jsakamoto commented 2 years ago

@stancoffyn Thank you for your contributions! 👍

Yes, the scenario you suggested would often happen, I think. Fortunately, the current library version already allows us to support this scenario with the following "indexer" syntax.

<h1>@Products[$"product{product.Id}name"]</h1>

(See also the "Note" section in the "Step.6 - Use the Text Table" chapter in the README )

Does it make sense to you?

stancoffyn commented 2 years ago

Perfectly, thank you. Sorry I didn't see that in the specs.

jsakamoto commented 2 years ago

@stancoffyn No problem! Anyway, thank you for your contributions! 👍