From b514f20784e95f6f3dc27f38598808f0c1c1ca26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wa=C5=82dis=20Iljuczonok?= Date: Mon, 24 Apr 2017 23:59:48 +0300 Subject: [PATCH] Update translate-enum-net.md --- docs/translate-enum-net.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/translate-enum-net.md b/docs/translate-enum-net.md index a3042bf2..dbd0bed7 100644 --- a/docs/translate-enum-net.md +++ b/docs/translate-enum-net.md @@ -1,4 +1,5 @@ # Translate System.Enum + It's quite often that you do have a enumeration in the domain to ensure that your entity might have value only from predefined list of values - like `Document.Status` or `PurchaseOrder.Shipment.Status`. These values are usually defined as `System.Enum`. And it's also quite often case when you need to render a list of these available values on the page or anywhere else for the user of the application to choose from. Now in 2.0 enumeration translation is easily available. ```csharp @@ -49,6 +50,23 @@ Or if you just need to output current status of the document to the end-user: @Model.Status.Translate() ``` +## Specify Translation for Enum + +By default name of the `Enum` member is taken as translation of the localizable resource. If you need to specify default translation for the resource, you can use `[Display]` attribute from `DataAnnotations` namespace: + + +```csharp +[LocalizedResource] +public enum DocumentStatus +{ + None, + New, + [Display(Name = "Pending document...")] Pending, + Active, + Closed +} +``` + ## Resource Keys for Enum Sometimes (usage for me was EPiServer visitor groups) you just need to control naming for each individual `Enum` item. Now you can do that with `[ResourceKey]` attribute. Hope code explains how it might look: