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

How to humanize enums from resource strings #323

Closed
EvgeniyKB opened this issue Aug 6, 2014 · 8 comments
Closed

How to humanize enums from resource strings #323

EvgeniyKB opened this issue Aug 6, 2014 · 8 comments

Comments

@EvgeniyKB
Copy link

A problem

Firstly, if there are several localizations for product they are located in Resources.resx files. So string literals are being chosed depended on current locale.

So my current code now is like this: resourceManager.GetString(stringToLocalize).
I can't place it to an attribute because ones arguments must be a const.

Secondly, we can write convention like this for enums:

resourceManager.GetString(enumName + "_" + enumMemberName)

Question

Are there any way to use resource strings for enum humanization in current version?
Can I make pull request for it?

@MehdiK
Copy link
Member

MehdiK commented Aug 7, 2014

I personally don't think this is something you should drive through Humanizer. Humanizer's added value is that it can Humanize your enums and as a bonus point fetch the description from Description attribute when it diverges from the member name. If you don't use the humanized member names, then I'm not sure why you would need Humanizer at all! You could very easily wrap your resourceManager.GetString(enumName + "_" + enumMemberName) in a method and call that directly.

@MehdiK MehdiK closed this as completed Aug 7, 2014
@ilizunov
Copy link

ilizunov commented Aug 8, 2014

Humanized string depends on current language. Rest of UI can be localized throw resources. Humanizer is to get some user-readable string from programmer-meaningful concept.
So EnumUnderTest. MemberWithDescriptionAttribute.Humanize() returns "Custom description".
But there are another languages but English. And I want to get "Descrição geral" in Portuguese.

There are localization for datetime, but how can I add localization for enum members?

@MehdiK
Copy link
Member

MehdiK commented Aug 10, 2014

I guess we could add a LocalizableDescription to Humanizer. Thoughts?

/cc @mexx @hazzik

@hazzik
Copy link
Member

hazzik commented Aug 11, 2014

👍

@mexx
Copy link
Collaborator

mexx commented Aug 11, 2014

With .NET 4.5 there is a DisplayAttribute with supports localization.
Should we support it instead of providing an own attribute?
For me it's a better solution, as with it the library where the enum is defined don't have to depend on Humanizer. I don't like this "base class" like problem.

@MehdiK
Copy link
Member

MehdiK commented Aug 12, 2014

IIRC DisplayAttribute doesn't work on enums. It's for classes and properties.

@mexx
Copy link
Collaborator

mexx commented Aug 12, 2014

It's also allowed on fields and works on enum members without problems.

@MehdiK
Copy link
Member

MehdiK commented Aug 16, 2014

I like it @mexx. The other great thing about Display is that unlike Description it's supported in PCL.

We can't remove the support for Description but we can add support for Display too. The funny thing is that even now you can apply Display on an enum and Humanizer will pick up the description out of it (because it has a string Description property on it) but it wouldn't know about or use the resources.

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

5 participants