Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 3 faster localization?

is there any way to speed up the string localization on ASp.Net mvc3 with razor? Lest say I write on my .cshtml "Hello World", and then I want to send that "Hello world" to the resources, with an automatic Id and refactor that string to the calling the resource, with just some clicks. Something like http://resourcerefactoring.codeplex.com/ but for VS 2010 and razor.

And Free!

Thanks!

like image 776
elranu Avatar asked May 24 '11 15:05

elranu


2 Answers

So I touch some few lines of the Resource Refactoring Tool and I make it work with Razor (cshtml files). You can find the source and the installer here: http://www.ranu.com.ar/2011/07/faster-localization-on-aspnet-mvc3-with.html

like image 194
elranu Avatar answered Oct 15 '22 18:10

elranu


I have used a helper for this, which get's a key for what you need to translate like this

@Html.Translate("MyHeader1")

and in the helper I took the value from the resources file I used, but you can also use a DB or what ever you want to getting the translation data.

String translated = (String)helper.ViewContext.HttpContext.GetGlobalResourceObject("Translation", key);

For development I add an # in front of the key, if no translation could be found, this way if I have something like #MyHeader1 in my user interace I know there is something I have to translate.

like image 28
tivo Avatar answered Oct 15 '22 20:10

tivo