Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
valdisiljuconoks authored and valdisiljuconoks committed Apr 24, 2017
2 parents a45bc96 + b514f20 commit 2a12b7f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/translate-enum-net.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2a12b7f

Please sign in to comment.