zHaytam / SmartBreadcrumbs

A utility library for ASP.NET Core (both MVC and Razor Pages) websites to easily add and customize breadcrumbs.
https://blog.zhaytam.com/2018/06/24/asp-net-core-using-smartbreadcrumbs/
MIT License
161 stars 77 forks source link

Allow localization of BreadCrumb Titles #28

Closed ConnerOrth closed 3 years ago

ConnerOrth commented 5 years ago

Make it possible for breadcrumbs to be localized.

zHaytam commented 5 years ago

How about something like:

[Breadcrumb("Key Lang", Localized = true, LocalizerType = typeof(SharedResource)]
// Or by default, use the controller type
[Breadcrumb("Key Lang", Localized = true)]

I can then use the IStringLocalizerFactory to create a IStringLocalizer and use it. Although for Razor Pages I'm not sure how localization works.

ConnerOrth commented 5 years ago

I would suggest to always run the title through localization, if a IStringLocalizerFactory has been added to the DI container. (You could create a property on the BreadcrumbOptions to hold a reference to the stringlocalizerfactory or the localizer resource?) And otherwise just return whatever title is passed.

That way you are not responsible for handling and/or maintaining the localization resource. You could potentially add a bool to prevent localizing a breadcrumb so like your suggestion but only use it to stop localizing.

Just thinking out loud here.

zHaytam commented 5 years ago

But in order to localize something, you need IStringLocaliser<> which needs to be injected and is generic. The only way you can create one is using the Factory and a Type.

How would the localization always be ran without these?

ConnerOrth commented 5 years ago

Check for existence of the factory, and if factory is not registered then do not run through translation, else use localizer.

zHaytam commented 5 years ago

So basically run localization whenever possible?

ConnerOrth commented 5 years ago

Yes this way it's up to the consumer of the breadcrumb package to provide the translation, if any.

cimermanalexander commented 4 years ago

Hi, I use this Breadcrumbs, there are nice, but i need this translations :) . Will you make that change in the future? It would be nice. :)

icesasoftcorp commented 4 years ago

what happened with this request?

Andrei0809 commented 4 years ago

Are there any updates on this issue?

zHaytam commented 4 years ago

Unfortunately, no. It's very hard to find the time for features like these 😞

julianyus commented 3 years ago

Hi, I also needed this functionality so I have implemented it. I'm going to do a pull request so we can see the code and see if the implementation can be improved.

zHaytam commented 3 years ago

Fixed in 3.6.0 thanks #78 (@julianyus).

icesasoftcorp commented 3 years ago

excellent, I will use

julianyus commented 3 years ago

Let me know if you have any problem or you need help with configuration.

icesasoftcorp commented 3 years ago

@julianyus and @zHaytam my English is not that good, make a change to your code, so that different namespaces can be used in language resources and no additional class needs to be created in the project.

if you allow me to submit my pull request for review

zHaytam commented 3 years ago

I am not sure I get what you kean, but a PR is welcome as always

icesasoftcorp commented 3 years ago

@zHaytam you add me as contributors, please

zHaytam commented 3 years ago

You need to Fork the project, do the modification in your repo then create a pull request

icesasoftcorp commented 3 years ago

sorry, you are right

icesasoftcorp commented 3 years ago

@zHaytam I send the PR for you review