Skip to content
itechnology edited this page Dec 5, 2012 · 11 revisions

#TOC

  • Basic Usage
  • Advance Usage
  • Configuration Options

Basic Usage

###Inside a non website project

  1. Drop T4ResX.tt inside any project containing RESX files, open it, and do a CTRL+S to save it. This will trigger the T4 code generation and output a strongly typed code in the form of T4ResX.cs. Now simply compile the project, and you now have a strongly typed assembly that you can use inside other projects.

###Inside web pages Once your localized assembly generated and compiled, include a reference to it in you website project. If you are not using a separate assembly to localize your files, simply drop T4ResX.tt in the root of your website project, double click to open it, do a CTRL+S to save it. Now your localized code is generated, and simply rebuild your site.

Then:

  1. Simply start writing code like @Resources.User.Pseudo or <%= Resources.User.Pseudo %> depending on whether you are using MVC or ASP.NET

###Localized JavaScript Once your localized assembly generated and compiled, include a reference to it in you website project.

Then :

  1. We first need to include a small helper method inside our project to be able to return JSON serialized content.
  2. We declare our method in our page or controller that returns the JSON generated above in the form of raw JavaScript.
  3. Include a <script src="/MyController/MyMethod?ns=NameSpaceToLoad"></script> inside whatever page you want to use localized JavaScript in.

#Advanced Usage (docs in progress....)

  • Formatting Variables
    • Doing things like Field {0}, must be different to field {1}
    • This for example is how MVC formats error messages
  • Replacement Variables
    • Doing things like Hello {0}, welcome to {BRAND}
      • This allows you to store replacement variables for things like, DOMAIN, BRAND, PRODUCTNAME inside a database or a configuration file, and have those variables replaced on the fly
  • Constants
  • Pulling parts out of the assembly in the form of Dictionary<string, Dictionary<string, string>>
    • This is how we are able to store text in RESX files and the extract parts of it into localized JavaScript files.

Clone this wiki locally