ASP.NET MVC 3 faster localization?

2019-03-25 21:30发布

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!

3条回答
Explosion°爆炸
2楼-- · 2019-03-25 21:46

Interesting.. I wasn't aware of that project as it seems pretty nice - too bad there haven't been recent updates to it. So is your question how to extract them easier, or develop using resource files from the start? Ideally you can just create on resource file, and use it directly by programming against the resource name to start - no extracting required then. You can simply copy and paste your resource files, rename them and change the language content. See

http://www.codecapers.com/post/How-to-Localize-an-ASPNET-MVC-Application.aspx

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-25 21:48

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.

查看更多
神经病院院长
4楼-- · 2019-03-25 21:52

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

查看更多
登录 后发表回答