Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log a message when ResourceManagerStringLocalizer cannot find a resource #43109

Open
1 task done
Vivelin opened this issue Aug 5, 2022 · 13 comments · May be fixed by #55897
Open
1 task done

Log a message when ResourceManagerStringLocalizer cannot find a resource #43109

Vivelin opened this issue Aug 5, 2022 · 13 comments · May be fixed by #55897
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-localization
Milestone

Comments

@Vivelin
Copy link

Vivelin commented Aug 5, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to localize my app. For this I am using IViewLocalizer from Razor Pages, and this works pretty well. However, there is no easy way for me to see which resources I have yet to localize.

Describe the solution you'd like

It would be incredibly helpful if there was a message that is logged when a string resource is missing and has yet to be localized.

A Debug-level message is logged when looking up resources:

Log.SearchedLocation(_logger, name, _resourceBaseName, keyCulture);

This is a start, but this message does not distinguish between strings it found and those that were missing.

I can search through the code using Find in Files to find all places where I use IStringLocalizer, IViewLocalizer and others, but that is error-prone and does not show me which ones have yet to be translated.

Additional context

No response

@javiercn javiercn added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-localization labels Aug 5, 2022
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Aug 8, 2022
@ghost
Copy link

ghost commented Aug 8, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed task labels Aug 8, 2022
@hishamco
Copy link
Member

I think we need ResourceLookupBehavior like the one @DamianEdwards mentioned here 8 years ago, with 3 options:

  1. Throw exception
  2. Log a message
  3. Use name as a value

If the team agreed to implement this feature, I'm ready to push a PR for it

@StepKie
Copy link

StepKie commented Feb 21, 2024

I just came across this because I am actually looking for a way to disable this behavior.

Currently, when using LogLevel Debug, I get hundreds of messages like

[0:] [19:32:01.051 DBG] ResourceManagerStringLocalizer searched for 'PlateGround' in 'MyApp.Resources.AppResources' with culture 'de-DE'.
[0:] [19:32:01.060 DBG] ResourceManagerStringLocalizer searched for 'GpsLatitude' in 'MyApp.Resources.AppResources' with culture 'de-DE'.
[0:] [19:32:01.071 DBG] ResourceManagerStringLocalizer searched for 'GpsLongitude' in 'MyApp.Resources.AppResources' with culture 'de-DE'.
[0:] [19:32:01.084 DBG] ResourceManagerStringLocalizer searched for 'WeatherYesterday' in 'MyApp.Resources.AppResources' with culture 'de-DE'.

These all exist and are not an indication of missing resx translation strings, it just merely reports everytime a XAML is parsed every single localization attempt.

Can this be turned off in any way?

@hishamco
Copy link
Member

Such logs are useful for debugging

@StepKie
Copy link

StepKie commented Feb 26, 2024

Such logs are useful for debugging

Yes, I did not question the usefulness.
But I would just like to be able to configure it somehow, because finding my own 6 Log.Debug statements in 200 lines of these messages gets old after a while...

@hishamco
Copy link
Member

We might change this behavior to log when the resource is missing or follow the suggestion above

/cc @DamianEdwards @sebastienros

@hishamco
Copy link
Member

hishamco commented May 7, 2024

@DamianEdwards do you agree with the above suggestion?

@DamianEdwards
Copy link
Member

@hishamco I think the simplest change would be to add a new log message that's emitted when a resource isn't found, probably at the debug level. If you want to send a PR for just that as a change I would think the team would be likely to accept it.

@hishamco
Copy link
Member

hishamco commented May 7, 2024

If I'm not wrong there's already a log message with the debug level if the resource is not found. I think I did a long time ago, let me check now

@hishamco
Copy link
Member

hishamco commented May 7, 2024

private static partial class Log
{
[LoggerMessage(1, LogLevel.Debug, $"{nameof(ResourceManagerStringLocalizer)} searched for '{{Key}}' in '{{LocationSearched}}' with culture '{{Culture}}'.", EventName = "SearchedLocation")]
public static partial void SearchedLocation(ILogger logger, string key, string locationSearched, CultureInfo culture);
}
}

That's what you mean, right?

@hishamco
Copy link
Member

hishamco commented May 7, 2024

Can this be turned off in any way?

@StepKie increase the log level, this is the matter of all debug logs :)

@DamianEdwards
Copy link
Member

As @Vivelin said in the issue description, that message doesn't indicate whether it was found or not, so I'm simply suggesting adding more messages to indicate the result of the search.

@hishamco
Copy link
Member

hishamco commented May 7, 2024

Right, I will submit a PR for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-localization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants