locked
Different Language resources files in coding RRS feed

  • Question

  • User-374095980 posted

     Dear all,

    I have made resources files for different lauguages, e.g. Resources.Fr.resx, Resources.US.resx...

    How to coding to make which resources files for default resources files so that when in the coding as below can be achieved with minimal coding change?

    this.lblcustomer.text=properties.resources.lblCustomer.toString();

    Then the label for customer text can be in US if we have chosen Resources.US.resx as default.

    Wednesday, December 8, 2010 2:33 AM

Answers

  • User712082397 posted

    Well, inaddition to this you would have to set the UICulture in the @Page directive. See here.

    you dont need to do coding for this, you can acheive this using meta:resourcekey in control tag

    There are several ways you do this. Its a matter of choice what technique you use. If you look at this MSDN article, they have shown how to do it programatically.

    But as I said, its a matter of choice.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 9, 2010 7:21 AM

All replies

  • User377791177 posted

    if i understand your question, u need to use

    GetLocalResourceObject("nameoftheresourcestring") function, u needn't bother about which language to pick framework takes care of that.

    Wednesday, December 8, 2010 3:41 AM
  • User-519136805 posted

    Hi,

    If you have generated resource file using Tools - Generate Local Resources option in VS 2005/8

    so your resource file will look like this in

    App_LocalResources

    >>HomePage.aspx.resx

    >>HomePage.aspx.nl-NL.resx

    >>HomePage.aspx.fr-FR.resx

    If this is your case than you need not to worry about code anything..

    It will be automatically setting labels text as per current Culture.

    You just need to update the culture of the site as language changes..

    Wednesday, December 8, 2010 9:11 AM
  • User712082397 posted

    Just make sure that you set this kind of code in your global.asax. This helps the resource manager to automatically pick the appropriate resource file

        Sub Application_BeginRequest(ByVal Sender As Object, ByVal e As EventArgs)
            Try
                'Set the current culture based on what the browser sends to the server 
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))
            Catch e As Exception
                'Give a default, if its not found
                Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
            End Try
            'set the current UI culture 
            'this will be used by the resource manager to retrieve values from resource files automatically 
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
        End Sub  ' Application_BeginRequest()


    And then you can use either GetGlobalResourceObject or GetLocalResourceObject(), depending on where your resource files are.

    Wednesday, December 8, 2010 11:09 AM
  • User-446044308 posted

    you dont need to do coding for this, you can acheive this using meta:resourcekey in control tag

    for example in textbox

    <asp:Textbox id="txt1" runat="server" meta:resourcekey="txt1">


    You will add txt1 resource info in all resource file

    Wednesday, December 8, 2010 1:40 PM
  • User-374095980 posted

    I will use resgen to generate different language resources files.

    But their filename is not resources.resx, they are resources.xxx.resx.

    If In the coding, I had used ......=properties.resources.lblcustomer.

    Then does it need to change to be GetLocalResources...(...) function?? 

    And Moreover, What is the mapping between the default resources.resx and used resources.xxx.resx??

    As I think there is a need to assign the resources.xxx.resx to be default resources file.

    Thursday, December 9, 2010 3:14 AM
  • User-446044308 posted

    yes you are right resource file name will be like Default.en-gb.resx 

    but you dont need coding if you assing metakey in control tag 

    Thursday, December 9, 2010 6:53 AM
  • User712082397 posted

    Well, inaddition to this you would have to set the UICulture in the @Page directive. See here.

    you dont need to do coding for this, you can acheive this using meta:resourcekey in control tag

    There are several ways you do this. Its a matter of choice what technique you use. If you look at this MSDN article, they have shown how to do it programatically.

    But as I said, its a matter of choice.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 9, 2010 7:21 AM
  • User-374095980 posted

    Dear all,

    Actually , I have the intranet application project with using properties.resources class. There is a resources.resx file.

    Now I have generated using resgen.exe from txt file into different languages resx file, e.g. resources.Fr.resx...( resgen fr.txt resources.Fr.resx)

    How to apply resources.resx or resources.Fr.resx  into the program with setting and configuration??

    e.g. In resources.designer.cs, it has culture setting. Is it related?

    Thursday, December 16, 2010 8:40 PM
  • User-519136805 posted

    The following code example gets a string resource using the specified culture.

    using System;
    using System.Globalization;
    using System.Threading;
    using System.Resources;
    using System.Reflection;
    
    class ResourcesExample 
    {
        public static void Main() 
        {
           // Create a resource manager to retrieve resources.
           ResourceManager rm = new ResourceManager("items", 
              Assembly.GetExecutingAssembly());
    
           // Get the culture of the currently executing thread.
           // The value of ci will determine the culture of
           // the resources that the resource manager retrieves.
           CultureInfo ci = Thread.CurrentThread.CurrentCulture;
    
           // Retrieve the value of the string resource named 
           // "welcome", localized for the culture specified by ci.
           String str = rm.GetString("welcome", ci);
           Console.WriteLine(str);
        }
    }
    

    Hope this helps !!!

    Saturday, January 1, 2011 1:22 AM