Transform ResX files into strongly typed classes via T4
- Sample WebSite
- Localized HTML, JavaScript & Code Behind
##Download
#Overview
##Have a project that uses ResX files ?
- Transform ResX files in a project into a strongly typed assembly
- Access your translations
- From inside .cshtml & .aspx files
@Resources.User.Pseudo
/<%= Resources.User.Pseudo %>
- From inside .cshtml & .aspx files
- Bind your translations to a ViewModel
[Display(Name = "Pseudo", ResourceType = typeof(Resources.User))]
- Use it again in your dlls to return localized error messages
return Resources.User.RegisterError;
####Use variables inside your ResX files
- Format various messages
- .resx:
Welcome {0}
- .cs:
return Resources.User.Welcome("Robert")
- result:
Welcome Robert
- .cs:
- .resx:
- Dynamically replace variables
- .resx:
Register with {DOMAIN}
- .cs:
return Resources.Branding.Register;
- result:
Register with www.i-technology.net
- .cs:
- .resx:
{BRAND} announces new feature for {0}
- .cs:
return Resources.Branding.Feature("T4")
- result:
I-Technology announces new feature for T4
- .cs:
- .resx:
####Export & Reuse your translations
- Pull translations directly into localized JavaScript files
<script src="/GetNameSpaceAsJs?ns=Resources.User"></script>
- Or assign inline
var localized = GetNameSpaceAsJson("Resources.User");
- Grab a series of translations as collection
Dictionary<string, Dictionary<string string>> items = GetResourcesByNameSpace("Resources.User");
- Or do just grab bits & pieces
Dictionary<string, Dictionary<string string>> items = GetResourcesByNameSpace(".*");
Dictionary<string, Dictionary<string string>> items = GetResourcesByNameSpace("Resources.User.*");
Dictionary<string, Dictionary<string string>> items = GetResourcesByNameSpace("^User|Branding");
##Updates
###0.99 / 2012-12-05
- First commit.
- Sample site up on Windows Azure @ t4resx.azurewebsites.net
- If it's down, it might be normal ..running on a free instance with daily resource limits
###0.991 / 2013-08-21 / author: dhlavaty
All resource keys are accessible by ResourceKey constants. So you can use compiler type checking for validation attributes:
[Required(ErrorMessageResourceName = Resources.User.RequiredErrorKey, ErrorMessageResourceType = typeof(Resources.User))]
instead of old version
[Required(ErrorMessageResourceName = "RequiredError", ErrorMessageResourceType = typeof(Resources.User))]
###0.992 / 2013-09-05 / author: dhlavaty Better c# XML documentation comments normalization, so you can use html tags in your localized texts
The end