2 min read Localization in C# is very straightforward. C# comes with Resource files, which are great because they can be easily translated, and C# can switch between them automatically.

First, add a new Resource File to your project. In my case, I called it SiteFields.resx. This will be the default language file, which in this case is English.

Next, we create a Localized Display Name Attribute, so we can leverage our ViewModels properly, instead of relying on text.

public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
    public LocalizedDisplayNameAttribute(string resourceId) : base(GetMessageFromResource(resourceId))
    {
    }
    private static string GetMessageFromResource(string resourceId)
    {
        CultureInfo culture = null;
        if (HttpContext.Current.Session["CultureInfo"] != null)
            culture = (CultureInfo)HttpContext.Current.Session["CultureInfo"];
        else
            culture = CultureInfo.CurrentCulture;
        return Resources.SiteFields.ResourceManager.GetString(resourceId, culture);
    }
}