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

Add Support for Nested Classes #8

Closed
Maskoe opened this issue Sep 9, 2024 · 8 comments
Closed

Add Support for Nested Classes #8

Maskoe opened this issue Sep 9, 2024 · 8 comments

Comments

@Maskoe
Copy link

Maskoe commented Sep 9, 2024

Hello, very cool library.

I would like to have just one Locale.json file per language.
I would structure it like this

Messages/T.json

{
  "Password": {
    "Uppercase": "Password needs at least one uppercase letter.",
    "Digit": "Password needs at least one number.",
    "Length": "Password must be at least 8 characters long."
  },
  "CreateUser": {
    "EmailInUse": "Email is already in use.",
    "InvalidRole": "Invalid role. Allowed roles are {roles}."
  }
}

I would like that to lead to

var err = T.Password.Uppercase;

Is that doable? If you dont want to do it, can you point me in a direction so I can give it a try?
Obviously while at it, it should probably work with any level of nesting. So I can really go ham and do T.Errors.CreateUser.InvalidRole.

@stefc
Copy link
Collaborator

stefc commented Sep 10, 2024

Very good suggestion !

@kl1mm
Copy link
Owner

kl1mm commented Sep 11, 2024

Hey @Maskoe,
sounds like a great improvement.
I am currently on vacation. I'll try to find time afterwards and see if I can incorporate your suggestion.
Please don't be angry if it takes longer.

Best regards mMilk

kl1mm added a commit that referenced this issue Sep 17, 2024
@kl1mm
Copy link
Owner

kl1mm commented Sep 17, 2024

Hey @Maskoe, @stefc
please try v1.0.4 and see if its fit your requiererments.

see the docs for more informations.

Best regards mMilk

@Maskoe
Copy link
Author

Maskoe commented Sep 17, 2024

I am constantly getting

The type or namespace name 'Locales' does not exist in the namespace 'LocTest' (are you missing an assembly reference?)

If I copy the generated class into my project and disable your source generator, it works.
I can also import the namespace just fine. It just wont let me build for some reason.

I got it to work once, but I have no idea what I did.
I tried different projects, solutions, setting namespace and class name manually, restarting rider 10 times.

I also have this warning in my console

0>CSC: Warning CS9057 : The analyzer assembly 'C:\Users\Mirco\.nuget\packages\kli.localize\1.0.4\analyzers\dotnet\cs\kli.Localize.Generator.dll' references version '4.11.0.0' of the compiler, which is newer than the currently running version '4.9.0.0'.

using LocTest.Locales;

namespace LocTest;

public class Testtt
{
    public void DoSomething()
    {
        var msg = T.Uppercase;
        Console.WriteLine(msg);
    }
}

Edit: Ahh found the difference.
If I turn on <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> in version 1.0.4 nothing happens.
If I turn it on on version 0.8.x I see my files in obj/debug/net8.0/generated

@kl1mm
Copy link
Owner

kl1mm commented Sep 17, 2024

@Maskoe, thanks for your feedback, i will have a look

@kl1mm
Copy link
Owner

kl1mm commented Sep 17, 2024

@Maskoe,
I have reset the expected compiler/sdk dependencies. I hope this helps you for now
=> v1.0.6

@Maskoe
Copy link
Author

Maskoe commented Sep 17, 2024

Yea works for me now. Its awesome.

Thats pretty much how every i18n library in the javascript world does it.

Was it a bug in your code or was it the weird compiler version thing?

@kl1mm
Copy link
Owner

kl1mm commented Sep 18, 2024

I'm glad to hear that it works. I'm still not 100% sure what is causing the problem.
It is under investigation :)

If you think the issue is resolved - feel free to close it.

best regards mMilk

@Maskoe Maskoe closed this as completed Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants