Yoeri
Yoeri

Reputation: 2249

End user wants to add languages dynamically to his website

We have to build an event registration website for our client in ASP.NET using C#. One of the requirements is that the client wants to add new foreign languages to his website himself using en excel file. I know how to make a website multilingual in Visual Studio, but I have no idea how to generate a resource file based on an excel file in code. I also noticed VS generates a second file called Resource.en.designer.cs but I can't find any documentation how to generate that file either.

btw, the enduser is anything but IT-related. He knows his way around excel though (obviously).

Any help is appreciated!

Yoeri

EDIT: !Robert Levy Provided a good method! HOW TO:

STEP 1: Read the excel file (using an OleDBAdapter was the best method for me, as you can use column headers etc) Write the language to a txt file in this format: KEY=TRANSLATION no spaces or anything else

STEP 2: Locate ResGen.exe on your computer (it comes with Visual Studio, so look somewhere like c:\program files\visual studio\sdk... however I found it @ C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe)

STEP 3:

Invoke the exe with Process.Start("resgen.exe") hint: use ProcesStartInfo for easy argument and preferences settings

(STEP 4:)

Move the file to your desired location (I find the App_GlobalResources works perfectly)

STEP 5:

Set the user currentUIculture to your desired culture!

Upvotes: 5

Views: 466

Answers (3)

Paweł Dyda
Paweł Dyda

Reputation: 18662

This is probably one place where you would like to use resources from database rather than simple resx files. It would be easier just to populate database table(s) with Excel data than transforming it to standard resx file (it could be a problem in the future if MS decided to modify file format).

So I would suggest you to write your own ResourceReader which would load strings from database (it could load it directly from Excel as well, but for many reasons I wouldn't recommend this method).

Upvotes: 1

Robert Levy
Robert Levy

Reputation: 29073

ResGen.exe will compile resource files for you. You could either get him to deliver text files in the format used by that tool or write your own code that extracts from excel to generate the text files. Then just invoke this EXE and deploy your newly generated resource DLL. I am assuming you already know how to read things from resource files and use the appropriate one based on user preference.

http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx

Upvotes: 2

Pleun
Pleun

Reputation: 8920

You should ask your end-user if they really have to get another language 'on the fly' and how many languages they expect they are going to add.

Otherwise, e-mailing the Excel file to you and manually creating the resource file might be by far the cheapest solution....

Upvotes: -1

Related Questions