question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Localization integration

See original GitHub issue

First of all a big thank you for maintaining this package. I am a big fan 😃

At the moment, however, I struggle, with the integration of string localization with the middleware. Ideally I would like to use IStringLocalizer to provide localized error messages. At the moment though we are using the middleware to intercept all errors and transform them in standardized ProblemDetails objects for our clients (including some enrichment with other properties). While I could throw the errors with localized strings, this would mean I would have to inject IStringLocalizer everywhere I throw an error. Is it possible somehow to incorporate this into the configuration of the AddProblemDetails middleware? Right now I have the following approach in my startup.cs

            services.AddProblemDetails(options =>
            {
                options.Map<BackendException>((ctx, ex) =>
                {
                    var provider = services.BuildServiceProvider();
                    var localizerFactory = provider.GetService<IStringLocalizerFactory>();
                    var localizer = new StringLocalizer<MyResources>(localizerFactory);

                    return new BackendProblemDetails
                    {
                        Title = string.Format(localizer[ex.ErrorIdentifier], ex.Parameters),
                        Type = ex.GetType().ToString(),
                        Status = (int)ex.StatusCode,
                        ...
                    };
                });
            });

However, the string localizer will not be injected with the desired culture 😦

Any ideas would be greatly apprecieated. Thanks / Mark

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
khellangcommented, Jul 12, 2021

Hmm, that’s weird 🤔

The mapping runs in the request pipeline (where UseProblemDetails is called), so it requires UseRequestLocalization to be called before UseProblemDetails in order for the localization to be properly set up.

I can see if I’m able to reproduce it when back behind a keyboard (currently on vacation 😅)

0reactions
markbangertcommented, Jul 12, 2021

I do use the official middleware for localization which works just fine at other parts of the code (e.g. within controllers) but not when setting up the PorblemDetails mapping in startup.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Software Integration Matters in Localization
Learn how to centralize data within your localization ecosystem and improve decision-making by leveraging software integration with Phrase.
Read more >
Integrations | Localization
Integrate Webflow with Localizer and allow visitors to see your content in their own language. Localize. Translation Management System that enables you to ......
Read more >
Lokalise: A Localization and Translation Software Tool
Lokalise is a continuous localization and translation management platform. It integrates into your development workflow so you can ship localized products, ...
Read more >
Integration with Localization Framework
Language translation fulfillers can provide translations faster and more efficiently by integrating with Localization Framework.
Read more >
Easier Localization With GitHub Integration
GitHub integration for Lokalise. Use our Github integration in your localization process to keep your source files and translations synchronized – seamlessly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found