Saturday, March 2, 2013

Internationalization in ASP.Net MVC Razor

More often internationalization is known as localization. The tools for the job are always the main decision factor in choosing the approach.

Last approach I used in an ASP.Net MVC site was using a resx for each culture. Didn't need (and also want) to replicate the views for each culture supported by the site. So I took every view and for each string needed to be internationalized, like a mindless robot :( , I iterated the folowing steps:

1. Selected the string
    2. Pressed the Ctrl+K,S then in Surround With popup pressed H, Tab, Q, Tab

    3. Back in the editor window, first notice the caret position (right after the legend tag and before the quote symbol), pressed Ctrl+Shift+] and the selection was remade(including quotes this time)

    4. Pressed Ctrl+R,Ctrl+X to show the Resource Refactor dialog (modified to be more proficient)

    5. There (because of my own ASP.Net MVC convention) I filled the prefix once for each new file I went through and proceeded with the string extraction and replacement with a property generated in the resx designer by the IDE.

    Note: Steps 1 and 2, sometimes were not needed (when the string was already had quotes). The Surround With script named quote was made by me, also as I mentioned the Resource Refactor VS extension was changed to allow a prefix for resource name.
    If you have a faster/smarter way, don't hesitate to leave a comment.

    Later edit:

    The step 2 needed an explanation for cryptic H and Q keys: H comes from HTML, Q comes from quote