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

[Localization] Missing the case when default namespace is different from assembly name #2502

Closed
tanaka-takayoshi opened this Issue Jan 12, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@tanaka-takayoshi

The document says:

the default namespace (which is also the name of the assembly)

In some cases, the default namespace is different from the assembly name. However, the document is missing for this case. The document should describe the available workaround for it. Or should clearly say "this is the limitation" if there's no workaround.

@Rick-Anderson

This comment has been minimized.

Show comment
Hide comment
@Rick-Anderson

Rick-Anderson Jan 12, 2017

Contributor

It goes on to say

Resources are named for the type of their class minus the default namespace (which is also the name of the assembly). For example, a French resource in the LocalizationWebsite.Web project for the class LocalizationWebsite.Web.Startup would be named Startup.fr.resx. The class LocalizationWebsite.Web.Controllers.HomeController would be Controllers.HomeController.fr.resx. If for some reason your targeted class is in the same project but not in the base namespace you will need the full type name. For example, in the sample project a type ExtraNamespace.Tools would be ExtraNamespace.Tools.fr.resx.

That should be rewritten to:

If your targeted class does not use the same namespace you will need the full type name.**

@ryanbrandenburg is this correct?

Contributor

Rick-Anderson commented Jan 12, 2017

It goes on to say

Resources are named for the type of their class minus the default namespace (which is also the name of the assembly). For example, a French resource in the LocalizationWebsite.Web project for the class LocalizationWebsite.Web.Startup would be named Startup.fr.resx. The class LocalizationWebsite.Web.Controllers.HomeController would be Controllers.HomeController.fr.resx. If for some reason your targeted class is in the same project but not in the base namespace you will need the full type name. For example, in the sample project a type ExtraNamespace.Tools would be ExtraNamespace.Tools.fr.resx.

That should be rewritten to:

If your targeted class does not use the same namespace you will need the full type name.**

@ryanbrandenburg is this correct?

@Rick-Anderson Rick-Anderson self-assigned this Jan 12, 2017

@Rick-Anderson Rick-Anderson added this to the 2017-Quarter 1 milestone Jan 12, 2017

@ryanbrandenburg

This comment has been minimized.

Show comment
Hide comment
@ryanbrandenburg

ryanbrandenburg Jan 12, 2017

Member

@Rick-Anderson I don't think that's what @tanaka-takayoshi is saying. I think he's saying that although by default most people will have the default namespace be the same as their assembly name that's not always the case, the two can be different. The determining factor is the HostingEnvironement.ApplicationName which is also the AssemblyName as far as I know.

We should remove the references to default namespace in that section.

@dougbu does that all sound accurate to you?

Member

ryanbrandenburg commented Jan 12, 2017

@Rick-Anderson I don't think that's what @tanaka-takayoshi is saying. I think he's saying that although by default most people will have the default namespace be the same as their assembly name that's not always the case, the two can be different. The determining factor is the HostingEnvironement.ApplicationName which is also the AssemblyName as far as I know.

We should remove the references to default namespace in that section.

@dougbu does that all sound accurate to you?

@Rick-Anderson

This comment has been minimized.

Show comment
Hide comment
@Rick-Anderson

Rick-Anderson Jan 13, 2017

Contributor

@ryanbrandenburg can you tap Edit link and make a first pass?

Can you include using resource files from another class ( a common question) - which I think is the same - using FQN.fr.resx

Contributor

Rick-Anderson commented Jan 13, 2017

@ryanbrandenburg can you tap Edit link and make a first pass?

Can you include using resource files from another class ( a common question) - which I think is the same - using FQN.fr.resx

@tanaka-takayoshi

This comment has been minimized.

Show comment
Hide comment
@tanaka-takayoshi

tanaka-takayoshi Jan 13, 2017

I debugged something with reading [ResourceManagerStringLocalizerFactory] (https://github.com/aspnet/Localization/blob/dev/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs) and @Rick-Anderson 's comment appears good.
At first, ApplicationName should be the AssemblyName. I think this is the current dotnet core specification and I confirmed when I specify the "name" in project.json, this become the application name and assembly name.

Then I tried two cases.

Case1)

If the class name of resource, which is the T of IStringLocalizer<T> or IHtmlLocalizer<T>, starts with the assembly name, we must abbreviate assembly name from class name. It means we can't specify the full class name.
e.g.:
assembly name: AspNetCore.StarterWeb
class name: AspNetCore.StarterWeb.Controllers.HomeController (used by IStringLocalizer<HomeController> )
resource file: Controllers.HomeController.ja.resx (in the case of Japanese resouce)
AspNetCore.StarterWeb.Controllers.HomeController.ja.resx is not working.

Case2)

If the class name of resource doesn't start with the assembly name, we must specify the full class name in resource file name.
e.g.:
assembly name: AspNetCore.StarterWeb
class name: WebApplication.Controllers.HomeController (used by IStringLocalizer<HomeController> )
resource file: WebApplication.Controllers.HomeController.ja.resx (in the case of Japanese resouce)

I debugged something with reading [ResourceManagerStringLocalizerFactory] (https://github.com/aspnet/Localization/blob/dev/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs) and @Rick-Anderson 's comment appears good.
At first, ApplicationName should be the AssemblyName. I think this is the current dotnet core specification and I confirmed when I specify the "name" in project.json, this become the application name and assembly name.

Then I tried two cases.

Case1)

If the class name of resource, which is the T of IStringLocalizer<T> or IHtmlLocalizer<T>, starts with the assembly name, we must abbreviate assembly name from class name. It means we can't specify the full class name.
e.g.:
assembly name: AspNetCore.StarterWeb
class name: AspNetCore.StarterWeb.Controllers.HomeController (used by IStringLocalizer<HomeController> )
resource file: Controllers.HomeController.ja.resx (in the case of Japanese resouce)
AspNetCore.StarterWeb.Controllers.HomeController.ja.resx is not working.

Case2)

If the class name of resource doesn't start with the assembly name, we must specify the full class name in resource file name.
e.g.:
assembly name: AspNetCore.StarterWeb
class name: WebApplication.Controllers.HomeController (used by IStringLocalizer<HomeController> )
resource file: WebApplication.Controllers.HomeController.ja.resx (in the case of Japanese resouce)

@Rick-Anderson

This comment has been minimized.

Show comment
Hide comment
Contributor

Rick-Anderson commented Jan 13, 2017

@tanaka-takayoshi Excellent!

@dougbu

This comment has been minimized.

Show comment
Hide comment
@dougbu

dougbu Jan 13, 2017

Member

@ryanbrandenburg your comments on assembly names are correct though @tanaka-takayoshi's cases make things more clear.

For one thing, there's no requirement that a C# namespace have any relationship to the assembly name. So mentioning the default namespace is somewhat off-topic except for the narrow case where users create classes in or below the default namespace and that default happens to be different from the assembly name e.g. because the assembly name contains special characters.

Member

dougbu commented Jan 13, 2017

@ryanbrandenburg your comments on assembly names are correct though @tanaka-takayoshi's cases make things more clear.

For one thing, there's no requirement that a C# namespace have any relationship to the assembly name. So mentioning the default namespace is somewhat off-topic except for the narrow case where users create classes in or below the default namespace and that default happens to be different from the assembly name e.g. because the assembly name contains special characters.

@ryanbrandenburg

This comment has been minimized.

Show comment
Hide comment
@ryanbrandenburg

ryanbrandenburg Jan 13, 2017

Member

I've made #2513 as a first run at clearing up that doc.

Member

ryanbrandenburg commented Jan 13, 2017

I've made #2513 as a first run at clearing up that doc.

@ryanbrandenburg

This comment has been minimized.

Show comment
Hide comment
@ryanbrandenburg

ryanbrandenburg Jan 13, 2017

Member

That's all merged in now, so closing this out.

Member

ryanbrandenburg commented Jan 13, 2017

That's all merged in now, so closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment