Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Resource name is incorrect when not setting Options.ResourcesPath #138

Closed
DamianEdwards opened this issue Nov 2, 2015 · 7 comments
Closed
Assignees
Milestone

Comments

@DamianEdwards
Copy link
Member

See the line at https://github.com/aspnet/Localization/blob/dev/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs#L68

If RequestLocalizationOptions.ResourcesPath is not set (the default) then this will effectively cause the application name to be appended to the beginning of the full type name, thus making it impossible to actually resolve that resource.

This means you can't just create a resx file next to a class' cs file with the same name and have it work, e.g. HomeController.cs and HomeController.en-AU.resx

The line should probably be something like:

var baseName = string.IsNullOrEmpty(_resourcesRelativePath)
                ? typeInfo.FullName
                : _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath + typeInfo.FullName;
@hishamco
Copy link
Contributor

hishamco commented Nov 2, 2015

Nice catch @DamianEdwards

@ryanbrandenburg
Copy link
Contributor

@DamianEdwards it appears that the current behavior when there's no ResourcePath is to find the resource in the root of the project, I assume we're OK loosing that functionality?

@DamianEdwards
Copy link
Member Author

No it doesn't. It ends up looking for a resource named "MyApplication..MyApplication.Full.TypeName". It's impossible to create a resource with that name, and the resource creation is non-configurable; it just gets named based on the name and path of the resx file in the project.

@ryanbrandenburg
Copy link
Contributor

@DamianEdwards that's my bad, for some reason my VS was running an old version of a project when I had saved changes to it which got me confused.

@DamianEdwards
Copy link
Member Author

@ryanbrandenburg
Copy link
Contributor

@DamianEdwards it looks like that case is taken care of by the "rootPath = location ?? _applicationEnvironment" above, right? The functional tests actually exercise this function and seem to get an acceptable baseName.

@DamianEdwards
Copy link
Member Author

Yeah you're right.

DamianEdwards added a commit that referenced this issue Dec 18, 2015
- Cleaned up code a little to make it easier to understand (maybe)
- #138
DamianEdwards added a commit that referenced this issue Dec 18, 2015
- Cleaned up code a little to make it easier to understand (maybe)
- #138
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants