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 — Generic Class and Localization not working #3422

Open
ckams opened this Issue Aug 13, 2018 · 17 comments

Comments

Projects
None yet
3 participants
@ckams

ckams commented Aug 13, 2018

May be a documentation issue, but I try here:

For non generic class, Localization works as expected. But with generic classes, seems that localization does not work.
 
I tried to localize Identities classes, like AppIdentityUser, I tried something like

  • AppIdentityUser.it.resx
  • AppIdentityUser<T>.it.resx
  • AppIdentityUser`1.it.resx (name get by reflection)

But nothing works. I cannot get the properties translated.

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 14, 2018

Contributor

@ckams can you provide a minimal repo to reproduce the issue

Contributor

hishamco commented Aug 14, 2018

@ckams can you provide a minimal repo to reproduce the issue

@ckams

This comment has been minimized.

Show comment
Hide comment
@ckams

ckams Aug 20, 2018

@hishamco
Not enough time, but you can easily try with MS samples on github.

ckams commented Aug 20, 2018

@hishamco
Not enough time, but you can easily try with MS samples on github.

@Eilon

This comment has been minimized.

Show comment
Hide comment
@Eilon

Eilon Aug 21, 2018

Member

Hi. We're closing this issue because we have been unable to reproduce it. If you have more details and are encountering this issue please add a new reply and re-open the issue.

Member

Eilon commented Aug 21, 2018

Hi. We're closing this issue because we have been unable to reproduce it. If you have more details and are encountering this issue please add a new reply and re-open the issue.

@Eilon Eilon closed this Aug 21, 2018

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 22, 2018

Contributor

Downloading & checking your sample ...

Contributor

hishamco commented Aug 22, 2018

Downloading & checking your sample ...

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 22, 2018

Contributor

At the first glance I didn't find a localize RegisterViewModel.resx in Resources\ViewModels\Account folder, seems that causes the issue .. I will try to add it and check your sample

Contributor

hishamco commented Aug 22, 2018

At the first glance I didn't find a localize RegisterViewModel.resx in Resources\ViewModels\Account folder, seems that causes the issue .. I will try to add it and check your sample

@ckams

This comment has been minimized.

Show comment
Hide comment
@ckams

ckams Aug 22, 2018

At the first glance I didn't find a localize RegisterViewModel.resx in Resources\ViewModels\Account folder, seems that causes the issue .. I will try to add it and check your sample

I do not think so. The location is related to the namespace.

ckams commented Aug 22, 2018

At the first glance I didn't find a localize RegisterViewModel.resx in Resources\ViewModels\Account folder, seems that causes the issue .. I will try to add it and check your sample

I do not think so. The location is related to the namespace.

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 22, 2018

Contributor

Yep, but there's no resource file related to the class, but seems the issue more than that I think I will start debugging the localization source ..

Contributor

hishamco commented Aug 22, 2018

Yep, but there's no resource file related to the class, but seems the issue more than that I think I will start debugging the localization source ..

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 22, 2018

Contributor

@Eilon I can confirm there's a bug, unless there's a special convention for naming resources for generic classes

But this is a first time I see someone trying to localize a generic class, nothing but still i'm not sure if we really need to localize such classes because T is a generic type

A workaround for this is creating a RegisterViewModel that inherits from RegisterViewModel<T> as the following:

    public class RegisterViewModel : RegisterViewModel<String>
    {

    }

@ckams this should work as usual ...

Contributor

hishamco commented Aug 22, 2018

@Eilon I can confirm there's a bug, unless there's a special convention for naming resources for generic classes

But this is a first time I see someone trying to localize a generic class, nothing but still i'm not sure if we really need to localize such classes because T is a generic type

A workaround for this is creating a RegisterViewModel that inherits from RegisterViewModel<T> as the following:

    public class RegisterViewModel : RegisterViewModel<String>
    {

    }

@ckams this should work as usual ...

@ckams

This comment has been minimized.

Show comment
Hide comment
@ckams

ckams Aug 23, 2018

Yep, but there's no resource file related to the class, but seems the issue more than that I think I will start debugging the localization source ..

@hishamco Are you sure? What that file?

But this is a first time I see someone trying to localize a generic class, nothing but still i'm not sure if we really need to localize such classes because T is a generic type

Well, if you want to localize Identity classes, you will soon see that we really need to localize such classes…

And, I do not want to use empty class as wrapper, and pollute my projects, just because ASP.NET Core MVC, is once again, buggy… But thanks @hishamco for all your engagement/serious. You are more professional than MS guys…

@Eilon you wrote:

Hi. We're closing this issue because we have been unable to reproduce it. If you have more details and are encountering this issue please add a new reply and re-open the issue.

This is not the first time I see this "kind of reply", whereas other are able—without any difficulties—to reproduce an issue… I do not know how you MS guys work, but seems not very serious/reassuring…

If you do not want to spend time on issue, do not lie, but rather, write—even with a "saved reply"

  • "We do not want to spend time in your issue…".

Finally, does anybody use ASP.NET Core MVC??? I often—not only me—find all kind of problems/limitations, on basic usages, as if it was a beta project…

ckams commented Aug 23, 2018

Yep, but there's no resource file related to the class, but seems the issue more than that I think I will start debugging the localization source ..

@hishamco Are you sure? What that file?

But this is a first time I see someone trying to localize a generic class, nothing but still i'm not sure if we really need to localize such classes because T is a generic type

Well, if you want to localize Identity classes, you will soon see that we really need to localize such classes…

And, I do not want to use empty class as wrapper, and pollute my projects, just because ASP.NET Core MVC, is once again, buggy… But thanks @hishamco for all your engagement/serious. You are more professional than MS guys…

@Eilon you wrote:

Hi. We're closing this issue because we have been unable to reproduce it. If you have more details and are encountering this issue please add a new reply and re-open the issue.

This is not the first time I see this "kind of reply", whereas other are able—without any difficulties—to reproduce an issue… I do not know how you MS guys work, but seems not very serious/reassuring…

If you do not want to spend time on issue, do not lie, but rather, write—even with a "saved reply"

  • "We do not want to spend time in your issue…".

Finally, does anybody use ASP.NET Core MVC??? I often—not only me—find all kind of problems/limitations, on basic usages, as if it was a beta project…

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 23, 2018

Contributor

Are you sure? What that file?

Strange!! seems I didn't notice that or got confused with your another project

Well, if you want to localize Identity classes, you will soon see that we really need to localize such classes…

Yep!!

@ckams ASP.NET team are working hard to release 2.2, if there's no reply that doesn't mean that you're ignored, believe it or not I filed some suggestions before year or so without reply but they keep there eyes or reply in the suitable time. BTW closing a bug is normal specially if there's no reply from the issuer or no repo to reproduce the bug

Anyhow, I will try to look into your repo again & come back to you ..

Contributor

hishamco commented Aug 23, 2018

Are you sure? What that file?

Strange!! seems I didn't notice that or got confused with your another project

Well, if you want to localize Identity classes, you will soon see that we really need to localize such classes…

Yep!!

@ckams ASP.NET team are working hard to release 2.2, if there's no reply that doesn't mean that you're ignored, believe it or not I filed some suggestions before year or so without reply but they keep there eyes or reply in the suitable time. BTW closing a bug is normal specially if there's no reply from the issuer or no repo to reproduce the bug

Anyhow, I will try to look into your repo again & come back to you ..

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 23, 2018

Contributor

@ckams are you sure the data annotations localization works in your repo?!! It didn't work on my end at all, even in en-US culture

Contributor

hishamco commented Aug 23, 2018

@ckams are you sure the data annotations localization works in your repo?!! It didn't work on my end at all, even in en-US culture

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 23, 2018

Contributor

Finally after debugging the localization source code, and while you are using RegisterViewModel<String> the generated class will have a fully qualified name for String, so the resource file should be named to RegisterViewModel`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].fr.resx I knew the name is weird but this how the generic class will be named, for that you need to provide n resource files per T

FYI I used Localization.StarterWeb sample that the one you provided because the data annotation isn't working at all

Contributor

hishamco commented Aug 23, 2018

Finally after debugging the localization source code, and while you are using RegisterViewModel<String> the generated class will have a fully qualified name for String, so the resource file should be named to RegisterViewModel`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].fr.resx I knew the name is weird but this how the generic class will be named, for that you need to provide n resource files per T

FYI I used Localization.StarterWeb sample that the one you provided because the data annotation isn't working at all

@ckams

This comment has been minimized.

Show comment
Hide comment
@ckams

ckams Aug 23, 2018

As I stated in my first message:

May be a documentation issue, but I try here:

So:

  1. Nowhere we can find this in the Doc.
  2. Obviously, this file name:
  • RegisterViewModel`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].fr.resx

is not a name usable normally, or MS guys are just crazy, or more likely, have missed this…

Anyway, Thanks again!

ckams commented Aug 23, 2018

As I stated in my first message:

May be a documentation issue, but I try here:

So:

  1. Nowhere we can find this in the Doc.
  2. Obviously, this file name:
  • RegisterViewModel`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].fr.resx

is not a name usable normally, or MS guys are just crazy, or more likely, have missed this…

Anyway, Thanks again!

@Eilon Eilon reopened this Aug 23, 2018

@Eilon

This comment has been minimized.

Show comment
Hide comment
@Eilon

Eilon Aug 23, 2018

Member

@ckams this indeed looks like a scenario we might not have considered before. We will take a further look at this and see what we can come up with.

Member

Eilon commented Aug 23, 2018

@ckams this indeed looks like a scenario we might not have considered before. We will take a further look at this and see what we can come up with.

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 23, 2018

Contributor
  1. Nowhere we can find this in the Doc.

@Rick-Anderson I think we need to mention this in the docs

Obviously, this file name:
RegisterViewModel`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].fr.resx

Yep, but the one you tried is RegisterViewModel1.fr.resx` 😄
@Eilon IMHO we can file another issue for resource naming cleanup for localize generic classes

Contributor

hishamco commented Aug 23, 2018

  1. Nowhere we can find this in the Doc.

@Rick-Anderson I think we need to mention this in the docs

Obviously, this file name:
RegisterViewModel`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].fr.resx

Yep, but the one you tried is RegisterViewModel1.fr.resx` 😄
@Eilon IMHO we can file another issue for resource naming cleanup for localize generic classes

@hishamco

This comment has been minimized.

Show comment
Hide comment
@hishamco

hishamco Aug 30, 2018

Contributor

FYI I added an extra property named UseGenericResources on LocalizationOptions to make it easier to control the resource name for generic class. I described everything in details in my blog post Localization & Generics

Contributor

hishamco commented Aug 30, 2018

FYI I added an extra property named UseGenericResources on LocalizationOptions to make it easier to control the resource name for generic class. I described everything in details in my blog post Localization & Generics

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