Tech Off Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

How can I add new resources to an Application ?

Back to Forum: Tech Off
  • User profile image
    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.

  • User profile image
    ZippyV

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

  • User profile image
    El Bruno

    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

  • User profile image
    Steve411

    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.

  • User profile image
    Grumpy

    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.

  • User profile image
    El Bruno

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


    Thanks Grumpy !!!

    But my problem is almost resolved, I want to know how to do this without rebuild the entire proyect.
    Let me be more speciffic, I want to modify a Resource file (outside the VS project) and compile it and set into the Asp.Net application, and I want the changes to be reflected.
    Or maybe, add a new resource file to the running Asp.Net file ...

    thanks again !!

  • User profile image
    JPeless

    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

  • User profile image
    El Bruno

    Thanks very much !!
    This works perfect !!!

    Thanks again from Spain
    El Bruno   

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.