Posted By: El Bruno | May 11th, 2005 @ 2:27 AM
page 1 of 1
Comments: 7 | Views: 14074
El Bruno
El Bruno
El Bruno
I made a sample application to test and learn the use of internationalization in Asp.Net. I generate the application, using resources files and I load all the "strings" to be displayed from the specified culture resource. for example:


Dim rm As ResourceManager = New ResourceManager("Menu.Sample", GetType(Menu.Sample).Assembly)
Label1.Text = rm.GetString("Label1")


 



I have a manager into a Base Class that manages the current culture for the specified user:



Dim sCul As String = HttpContext.Current.Session("cul")
' carga los datos de la cultura desde la session
If sCul <> "" Then
Dim cul As String = HttpContext.Current.Session("cul")
Dim culture As CultureInfo = New CultureInfo(cul)
System.Threading.Thread.CurrentThread.CurrentUICulture = culture
System.Threading.Thread.CurrentThread.CurrentCulture = culture
End If

 


Now application is running OK.
But I want to add new languages, I mean new resource files.
I create a new resource file but I don't know how can I agregate to the existing ones. The resources files have the .resx extentions. I use the Regres and I generate the .resources files. But I must generate a .dll file.

Any suggestions ?

El Bruno

PD: My final website folder is like this

Menu
  - bin
    - en-US
       Menu.resources.dll
    - es-ES
       Menu.resources.dll
    Menu.dll
    Menu.pdb

Sorry for my poor English.

ZippyV
ZippyV
Fired Up

Edited: you can include more than 1 resx file into a dll.

El Bruno wrote:

Thanks.
But I want to know the (few?) steps to do this.
Asume I've already running my app, and I want to add or update some resources ?

I can't find the correct steps to perform this

Bye from Spain.
El Bruno


Enjoy.
Basically I add a new resource file to my project, then rename the file with the appropriate culture code.  I then copy the data keys from the default resource file into the new culture resource file and change as appropriate.

So if I had an ASP.NET project with the file test.aspx.resx as my default resource file, I would add a new resource file for English with the name test.aspx.en.resx and add another resource file for Spanish with the name test.aspx.es.resx.  Now copy the <data> elements from test.aspx.resx and place them in test.aspx.en.resx and test.aspx.es.resx.  Then edit the <value> element contents as appropriate for the culture.

Once I rebuild my project, VS.NET will create the appropriate structure under the bin directory.

If you want to define a more specifc culture resource files, you can just use that culture identifier code.  So in your example, you use en-US and es-ES.  This would translate in my example to be the files: test.aspx.en-us.resx and test.aspx.es-es.resx.  Along with these files you could still have the other files: test.aspx.en.resx and test.aspx.es.resx.

When your user is associated with the culture identifier en-UK, the .NET framework will see only the resource files for en and en-US.  It doesn't find en-UK so it strips the the -UK and will find the en resource file and use it.  If you didn't have the en resource file, the .NET framework will use the default resoruce file as a last resort.

Hope that helps, Grumpy.
These are two lines from a .bat file I run to generate my satellite resource assemblies, of course, these are string only resource files.

This is an example for a Spanish resource file.

resgen TCResx.es.txt TCResx.es.resources
al /embed:TCResx.es.resources,TCResx.es.resources /culture:es /out:TCResx.resources.dll
page 1 of 1
Comments: 7 | Views: 14074
Microsoft Communities