Locale support for address labels

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Nagy

    Locale support for address labels

    Hiyas

    Our app has a search field where you can select a country drop down
    and then enter some search criteria that is address based. We want the
    labels on the search form to change based on what country you select.
    For example, if I select UK, it might ask for District and Borough
    (sp?). Whereas if I select Australia, I need it to say State and
    Postcode. For the US it might say Zip instead.

    I figure best way is to store all these labels in a resx file by
    locale, and when I select UK from ddl, it passes en-uk locale to my
    control, which loads the correct labels.

    Before I start typing out all the locales in my resx file, I'd like to
    know if it already exists. No doubt it does, but couldn't find it by
    searching. Anyone know of such a file or even a control that supports
    it all?

    Cheers,
    Steve
  • Alexey Smirnov

    #2
    Re: Locale support for address labels

    On Aug 5, 6:26 am, Steven Nagy <learndot...@ho tmail.comwrote:
    Hiyas
    >
    Our app has a search field where you can select a country drop down
    and then enter some search criteria that is address based. We want the
    labels on the search form to change based on what country you select.
    For example, if I select UK, it might ask for District and Borough
    (sp?). Whereas if I select Australia, I need it to say State and
    Postcode. For the US it might say Zip instead.
    >
    I figure best way is to store all these labels in a resx file by
    locale, and when I select UK from ddl, it passes en-uk locale to my
    control, which loads the correct labels.
    >
    Before I start typing out all the locales in my resx file, I'd like to
    know if it already exists. No doubt it does, but couldn't find it by
    searching. Anyone know of such a file or even a control that supports
    it all?
    >
    Cheers,
    Steve
    Hi Steve,

    here's a list of cultures
    Provides information about a specific culture (called a locale for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.


    and here is an example of using resx for a label customization


    Hope this helps

    Comment

    • Steven Nagy

      #3
      Re: Locale support for address labels

      Thanks Alexey,

      Do you (or anyone) know if you can set the locale for a specific
      control only?
      Lets say my CurrentThread.C urrentUICulture is set to en-US and I want
      this to remain as is (loading all the resources for en-US) but I want
      to change the locale for just one control to en-UK so that those
      resources are loaded for that control instead.
      Is this possible?

      Cheers,
      Steve

      Comment

      • Alexey Smirnov

        #4
        Re: Locale support for address labels

        On Aug 5, 12:49 pm, Steven Nagy <learndot...@ho tmail.comwrote:
        Thanks Alexey,
        >
        Do you (or anyone) know if you can set the locale for a specific
        control only?
        Lets say my CurrentThread.C urrentUICulture is set to en-US and I want
        this to remain as is (loading all the resources for en-US) but I want
        to change the locale for just one control to en-UK so that those
        resources are loaded for that control instead.
        Is this possible?
        >
        Cheers,
        Steve
        If you understood you correct, you could do it per control as follows

        <asp:Label ID="ZIPCodeLabe l" Runat="server" Text="<%$
        Resources:Local izedText, ZIPname %>">

        For US it would be a "ZIP", for Canada/Europe a "Postal Code", etc.

        You could also check the current culture and decide if control/string
        needs to be translated or not

        if (Thread.Current Thread.CurrentC ulture.Name == "en-US") {
        ....
        } else {
        ....
        }

        or

        System.Globaliz ation.CultureIn fo culture = new
        System.Globaliz ation.CultureIn fo("en-US");
        HttpContext.Get GlobalResourceO bject("resource ", "ZIPname", culture);

        where GetGlobalResour ceObject is to retrieve the resource value
        ("ZIPname") from global resource file, named Resource.resx
        programmaticall y




        Basically the idea of using resources is to have the translation for
        all "strings" in the application. And an application loads the
        appropriate localized resources based on the current culture.

        Comment

        • Steven Nagy

          #5
          Re: Locale support for address labels

          Ah this is the code I was after:

          System.Globaliz ation.CultureIn fo culture = new
          System.Globaliz ation.CultureIn fo("en-US");
          HttpContext.Get GlobalResourceO bject("resource ", "ZIPname", culture);
          Means I can have my single control changed to a different culture, and
          have the labels loaded for that culture, while the rest of hte
          application still sits in a different culture.

          Thanks!

          Comment

          • Alexey Smirnov

            #6
            Re: Locale support for address labels

            On Aug 6, 12:51 am, Steven Nagy <learndot...@ho tmail.comwrote:
            Ah this is the code I was after:
            >
            System.Globaliz ation.CultureIn fo culture = new
            System.Globaliz ation.CultureIn fo("en-US");
            HttpContext.Get GlobalResourceO bject("resource ", "ZIPname", culture);
            >
            Means I can have my single control changed to a different culture, and
            have the labels loaded for that culture, while the rest of hte
            application still sits in a different culture.
            >
            Thanks!

            Yes, you can.

            Note, there is also the GetLocalResourc eObject method to get a page-
            level resource (not the global one)


            for example

            System.Globaliz ation.CultureIn fo culture = new
            System.Globaliz ation.CultureIn fo("en-US");
            GetLocalResourc eObject("~/Default.aspx", "PageResource1. Title",
            culture);

            Hope this helps

            Comment

            Working...