Code Monkey home page Code Monkey logo

Comments (7)

KalleOlaviNiemitalo avatar KalleOlaviNiemitalo commented on June 12, 2024 1

If a developer has written [HandleCommand("foo", Description="Do the bar thing")] and then needs to make the description localisable, how would they change the code?

from command-line-api.

carstencodes avatar carstencodes commented on June 12, 2024

We're currently using CommandLineParser in most of our Projects. They solve it as follows:

Adding the HelpText will use the Text supplied. If ResourceType is set, than it will be used as the HelpText Resource Provider:

[HandleCommand("foo", Description=nameof(Resources.SR_FooCommandDescription), DescriptionResource=typeof(Resources))]

I would also prefer using System.Component.DescriptionAttribute, but as far as I am concerned, it is not localizable either, is it?

What do you think?

from command-line-api.

carstencodes avatar carstencodes commented on June 12, 2024

Most equivalent work is also present in System.ComponentModel and System.ComponentModel.DataAnnotations. It would be good to support it this way.

from command-line-api.

carstencodes avatar carstencodes commented on June 12, 2024

Please note, that I am also willing to contribute the implementation for this, but I won't create an implementation and add much effort into it, if the PR will be close because this is not wanted or even added to the scope by the maintainers.

from command-line-api.

KalleOlaviNiemitalo avatar KalleOlaviNiemitalo commented on June 12, 2024

DescriptionAttribute itself is not localizable, but derived classes can load the description from resources, like here: https://github.com/dotnet/runtime/blob/bf5e279d9239bfef5bb1b8d6212f1b971c434606/src/libraries/System.ComponentModel.TypeConverter/src/System/Timers/TimersDescriptionAttribute.cs#L24

I suppose a source generator could support that by translating [CustomDescription("ResourceKey")] to new CustomDescriptionAttribute("ResourceKey").Description if it detects that CustomDescriptionAttribute is based on DescriptionAttribute.

from command-line-api.

elgonzo avatar elgonzo commented on June 12, 2024

Just as an FYI, there is already a 3rd-party project that is trying to do what you seek: #2310 (based on the System.CommandLine version available on the public nuget.org and not on the newer System.CommandLine code base as present in the repository here, as it seems). It supports code generation but it seems to lack localization features as of now.

from command-line-api.

carstencodes avatar carstencodes commented on June 12, 2024

Awesome!

from command-line-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.