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

Localization — Generic Class and Localization not working #3422

Closed
ghost opened this issue Aug 13, 2018 · 18 comments
Closed

Localization — Generic Class and Localization not working #3422

ghost opened this issue Aug 13, 2018 · 18 comments
Labels

Comments

@ghost
Copy link

@ghost ghost 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
Copy link
Contributor

@hishamco hishamco commented Aug 14, 2018

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

@ghost
Copy link
Author

@ghost ghost commented Aug 20, 2018

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

@Eilon
Copy link
Member

@Eilon 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
Copy link
Contributor

@hishamco hishamco commented Aug 22, 2018

Downloading & checking your sample ...

@hishamco
Copy link
Contributor

@hishamco 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

@ghost
Copy link
Author

@ghost ghost 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
Copy link
Contributor

@hishamco 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
Copy link
Contributor

@hishamco 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 ...

@ghost
Copy link
Author

@ghost ghost 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
Copy link
Contributor

@hishamco 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
Copy link
Contributor

@hishamco 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
Copy link
Contributor

@hishamco 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

@ghost
Copy link
Author

@ghost ghost 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
Copy link
Member

@Eilon 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
Copy link
Contributor

@hishamco 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
Copy link
Contributor

@hishamco 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

@mkArtakMSFT
Copy link
Contributor

@mkArtakMSFT mkArtakMSFT commented Nov 7, 2018

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

@mkArtakMSFT mkArtakMSFT closed this Nov 7, 2018
@msftbot msftbot bot locked as resolved and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants