ASP.NET MVC 3 faster localization? - visual-studio-2010

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!

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

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.

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

Related

Literal control in asp net core 2.0

I've been searching for another way to do the same thing the asp.net literal control used to do. For those who don't know it, it allows us to format HTML and store it in a database, for instance, and when we load it is already formatted. Personally, I don't quite like to do this, but I'm working on a project where the company implemented it like this, so unless they agree to change it, I'll have to find a solution for this.
So, is there any way reach the same end as the literal control did?

How to use language files in MVC3?

right now I am typing out my messages in the controllers I use like this:
TempData["flashError"] = "There Was A Problem Updating Your Account, Please Try Again";
I would like to reference a key/value system such as:
TempData["flashError"] = Messages["accountProblem"];
Is there a certain way to do this so I can maintain my messages from a separate file? Can someone tell me best practice?
You may take a look at the following guide. You'd basically externalize the messages into resource files for each language and then you could use the strongly typed class that is automatically generated by Visual Studio to access those strings in your code.
to add to Darin's answer
there's a sample application that uses resource files for MUI
you can download it from here: http://prodinner.codeplex.com
it also has a code walkthrough pdf file
also, see it live: http://prodinner.aspnetawesome.com

How to variables from a textfile into a C# script

I need to create a text file for a game designer to edit variables in my C# script. I would like to be able to write the variable in the text file and the designer can put in a value and hten it would change in my script.
However, after much searching I have not been able to find a solution to my problem and was hoping someone with some experience in this method could help me.
I'm using Visual Studio for writing my scripts and the designer would require Notepad.
Thanks,
Chris
You can try using this class that will allow you to use ini files to hold your configuration.
I'm assuming your designer wouldn't like to use XML (which is the .NETy way of doing things); making humans edit XML is a form of torture anyway.
Here's the link to the CodeProject page: An INI file handling class using C#.
You can also use some other (relatively simple) format like JSON if ini files are too flat for you.

Visual Studio extensions for code generation...what's the best way

So we have this tool, it's a web page, we drop a large piece of text in textBox a (say sql) run the tool
and it generates the guts of a code file in TextBoxb (say a custom view class model).
it's written in C#.
I know there are several ways to create visual studio extensions.
What I'd like to know is, what's the best/easiest/fastest way to take a c# dll that has a method that takes text in and returns text out, and turn it into a VisualStudio extenson, that takes text in and creates a files, adds it to the project and puts the text into it.
We're using Vs2008 and VS2010, and I'm okay the best soloution only work on 2010.
The closest I've found by googling so far is this:
http://visualstudiomagazine.com/articles/2009/03/01/generate-code-from-custom-file-formats.aspx
but they are for custom file formats only, i want to generate*.cs and *.rdlc and similar files.
I'd also like to be able to add methods to an existing class.
tutorial walkthroughs or better approaches woud be greatly appreicated.
VS package Builder is the answer. Lots easier.

Load MS Word files with AJAX

I want to dynamically load (AJAX) the text from some Microsoft Word files into a webpage. So I might have a link to essays I've written and upon mouseover have it load the first few sentences in a tooltip.
Only if you have a parser. I think the new format is a zip archive with XML schema. But the old one is just binary.
There are some parsers out there.
I know of wvWare but it seems it's outdated. (http://wvware.sourceforge.net/)
This is maybe something worth looking at: http://poi.apache.org/hwpf/index.html
And yeah, forgot to mention how to do this. :-)
First you need to make the javascript ask for the data through ajax. The serverside has to take care of the parsing and return the text to the javascript. This will be a pain in the ass. I haven't done this myself and have never tried the parsers I linked, so I'm not sure if they suit you. Images, stylesheets, etc.... not sure if that will be useable.
At least, good luck.
For security reasons, it is not possible to directly load a local file (such as a Word document) into the page using simply Javascript. The user will need to upload the file to the server, which you will want to parse on the server and then you can load whatever result you like into the page using Ajax.
It sounds like you mean to upload your files (e.g. essays) to your server to allow users to download them, and want to create a server-side page that will parse the files and print the first few lines (so it can be called by an AJAX method that displays a preview on hover).
To suggest a tool for this, we'll need to know whether these are "old" Word format (Office 2003 - extension is .doc) or "new" Word format (Office 2007 - extension is .docx).
It will also be good to know what you're using to create your pages server-side, since different document-reading tools support different programming languages. If you're using Java to read .doc files, you can use the tool we use at my place of work, which is POI (http://poi.apache.org/). If you're using something else, try searching google for {read in }, e.g. {read .docx in ruby}.
If all of this is Greek to you and you have no prior experience with developing custom server-side web code, this is probably going to be unnecessarily painful and you should consider an alternative (like manually creating a 3-line text "preview" page for each regular page, and then just showing that).

Resources